5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2007 Novell, Inc. http://www.novell.com
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 internal class XmlBinaryFormat
36 public const byte EndElement = 0x01;
37 public const byte Comment = 0x02;
38 public const byte Array = 0x03;
39 public const byte AttrString = 0x04;
40 public const byte AttrStringPrefix = 0x05;
41 public const byte AttrIndex = 0x06;
42 public const byte AttrIndexPrefix = 0x07;
43 public const byte DefaultNSString = 0x08;
44 public const byte PrefixNSString = 0x09;
45 public const byte DefaultNSIndex = 0x0A;
46 public const byte PrefixNSIndex = 0x0B;
47 public const byte PrefixNAttrIndexStart = 0x0C;
48 public const byte PrefixNAttrIndexEnd = 0x0C + 26 - 1;
49 public const byte PrefixNAttrStringStart = 0x26;
50 public const byte PrefixNAttrStringEnd = 0x26 + 26 - 1;
51 public const byte ElemString = 0x40;
52 public const byte ElemStringPrefix = 0x41;
53 public const byte ElemIndex = 0x42;
54 public const byte ElemIndexPrefix = 0x43;
55 public const byte PrefixNElemIndexStart = 0x44;
56 public const byte PrefixNElemIndexEnd = 0x44 + 26 - 1;
57 public const byte PrefixNElemStringStart = 0x5E;
58 public const byte PrefixNElemStringEnd = 0x5E + 26 - 1;
60 public const byte Zero = 0x80;
61 public const byte One = 0x82;
62 public const byte BoolFalse = 0x84;
63 public const byte BoolTrue = 0x86;
64 public const byte Int8 = 0x88;
65 public const byte Int16 = 0x8A;
66 public const byte Int32 = 0x8C;
67 public const byte Int64 = 0x8E;
68 public const byte Single = 0x90;
69 public const byte Double = 0x92;
70 public const byte Decimal = 0x94;
71 public const byte DateTime = 0x96;
72 public const byte Chars8 = 0x98;
73 public const byte Chars16 = 0x9A;
74 public const byte Chars32 = 0x9C;
75 public const byte Bytes8 = 0x9E;
76 public const byte Bytes16 = 0xA0;
77 public const byte Bytes32 = 0xA2;
79 public const byte EmptyText = 0xA8;
80 public const byte TextIndex = 0xAA;
81 public const byte UniqueId = 0xAC;
82 public const byte TimeSpan = 0xAE;
83 public const byte Guid = 0xB0;
84 public const byte UInt64 = 0xB2;
85 public const byte Bool = 0xB4; // e.g. for typed array
86 public const byte Utf16_8 = 0xB6;
87 public const byte Utf16_16 = 0xB8;
88 public const byte Utf16_32 = 0xBA;
89 public const byte QNameIndex = 0xBC;
92 /* Binary Format (incomplete):
94 Literal strings are represented as UTF-8 string, with a length
95 prefixed to the string itself.
97 Key indices are based on the rules below:
98 - dictionary strings which can be found in IXmlDictionary are
99 doubled its Key. e.g. if the string.Key is 4, then the
101 - dictionary strings which cannot be found in IXmlDictionary
102 are stored in the XmlBinaryWriterSession, and its output
103 number is doubled + 1 e.g. if the string is the first
104 non-dictionary entry, then the output is 1, and 7 for the
106 - When the index goes beyond 128, then it becomes 2 bytes,
107 where the first byte becomes 0x80 + idx % 0x80 and
108 the second byte becomes idx / 0x80.
110 Below are operations. Prefixes are always raw strings.
111 $string is length-prefixed string. @index is index as
112 described above. [value] is length-prefixed raw array.
114 // 2009-03-25: now that the binary format is open under OSP
115 // [MC-NBFX], I have added some notes beyond current
116 // implementation status (marked as TODO).
121 04 $name : local attribute by string
122 05 $prefix $name : global attribute by string
123 06 @name : local attribute by index
124 07 $prefix @name : global attribute by index
125 08 $name : default namespace by string
126 09 $prefix $name : prefixed namespace by string
127 0A @name : default namespace by index
128 0B $prefix @name : prefixed namespace by index
129 0C @name : global attribute by index,
130 ... 0x25 : in current element's namespace
131 26 ... 0x3F : attributes with prefix
132 40 $name : element w/o namespace by string
133 41 $prefix $name : element with namespace by string
134 42 @name : element w/o namespace by index
135 43 $prefix @name : element with namespace by index
136 44 @name : global element by index,
137 ... 0x5D : in current element's namespace
138 5E ... 0x77 : elements with prefix
139 98 $value : text/cdata/chars
140 99 $value : text/cdata/chars + EndElement
142 FIXME: Below are not implemented:
143 (Uri is simply 98, QName is 98 '{' ns '}' 98 name)
145 Combined EndElement for below are supported:
162 A0 : bytes16 (base64)
163 A2 : bytes32 (base64)
164 A4 : TODO: start of list
165 A6 : TODO: end of list
168 AC : UniqueId (IsGuid = true)