XmlBinaryFormat.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // XmlBinaryFormat.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2007 Novell, Inc. http://www.novell.com
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. namespace System.Xml
  31. {
  32. internal class XmlBinaryFormat
  33. {
  34. public const byte EndElement = 0x01;
  35. public const byte Comment = 0x02;
  36. public const byte AttrString = 0x04;
  37. public const byte AttrStringPrefix = 0x05;
  38. public const byte AttrIndex = 0x06;
  39. public const byte AttrIndexPrefix = 0x07;
  40. public const byte DefaultNSString = 0x08;
  41. public const byte PrefixNSString = 0x09;
  42. public const byte DefaultNSIndex = 0x0A;
  43. public const byte PrefixNSIndex = 0x0B;
  44. public const byte GlobalAttrIndex = 0x0C;
  45. public const byte GlobalAttrIndexInElemNS = 0x0D;
  46. public const byte AttrTempIndexPrefixStringStart = 0x26;
  47. public const byte AttrTempIndexPrefixStringEnd = 0x26 + 26 - 1;
  48. public const byte ElemString = 0x40;
  49. public const byte ElemStringPrefix = 0x41;
  50. public const byte ElemIndex = 0x42;
  51. public const byte ElemIndexPrefix = 0x43;
  52. public const byte Zero = 0x80;
  53. public const byte One = 0x82;
  54. public const byte BoolFalse = 0x84;
  55. public const byte BoolTrue = 0x86;
  56. public const byte Int8 = 0x88;
  57. public const byte Int16 = 0x8A;
  58. public const byte Int32 = 0x8C;
  59. public const byte Int64 = 0x8E;
  60. public const byte Single = 0x90;
  61. public const byte Double = 0x92;
  62. public const byte Decimal = 0x94;
  63. public const byte DateTime = 0x96;
  64. public const byte Chars8 = 0x98;
  65. public const byte Chars16 = 0x9A;
  66. public const byte Chars32 = 0x9C;
  67. public const byte Bytes8 = 0x9E;
  68. public const byte Bytes16 = 0xA0;
  69. public const byte Bytes32 = 0xA2;
  70. public const byte EmptyText = 0xA8;
  71. public const byte UniqueId = 0xAC;
  72. public const byte TimeSpan = 0xAE;
  73. public const byte Guid = 0xB0;
  74. }
  75. /* Binary Format (incomplete):
  76. Literal strings are represented as UTF-8 string, with a length
  77. prefixed to the string itself.
  78. Key indices are based on the rules below:
  79. - dictionary strings which can be found in IXmlDictionary are
  80. doubled its Key. e.g. if the string.Key is 4, then the
  81. output is 8.
  82. - dictionary strings which cannot be found in IXmlDictionary
  83. are stored in the XmlBinaryWriterSession, and its output
  84. number is doubled + 1 e.g. if the string is the first
  85. non-dictionary entry, then the output is 1, and 7 for the
  86. fourth one.
  87. - When the index goes beyond 128, then it becomes 2 bytes,
  88. where the first byte becomes 0x80 + idx % 0x80 and
  89. the second byte becomes idx / 0x80.
  90. Below are operations. Prefixes are always raw strings.
  91. $string is length-prefixed string. @index is index as
  92. described above. [value] is length-prefixed raw array.
  93. // 2009-03-25: now that the binary format is open under OSP
  94. // [MC-NBFX], I have added some notes beyond current
  95. // implementation status (marked as TODO).
  96. 01 : EndElement
  97. 02 $value : Comment
  98. 03 : TODO: array
  99. 04 $name : local attribute by string
  100. 05 $prefix $name : global attribute by string
  101. 06 @name : local attribute by index
  102. 07 $prefix @name : global attribute by index
  103. 08 $name : default namespace by string
  104. 09 $prefix $name : prefixed namespace by string
  105. 0A @name : default namespace by index
  106. 0B $prefix @name : prefixed namespace by index
  107. 0C @name : global attribute by index,
  108. ... 0x25 : in current element's namespace
  109. 26 ... 0x3F : attributes with prefix
  110. 40 $name : element w/o namespace by string
  111. 41 $prefix $name : element with namespace by string
  112. 42 @name : element w/o namespace by index
  113. 43 $prefix @name : element with namespace by index
  114. 44 @name : global element by index,
  115. ... 0x5D : in current element's namespace
  116. 5E ... 0x77 : TODO: elements with prefix
  117. 98 $value : text/cdata/chars
  118. 99 $value : text/cdata/chars + EndElement
  119. FIXME: Below are not implemented:
  120. (Uri is simply 98, QName is 98 '{' ns '}' 98 name)
  121. Combined EndElement for below are supported:
  122. 80 : 0 (integer)
  123. 82 : 1 (integer)
  124. 84 : false (bool)
  125. 86 : true (bool)
  126. 88 : 1-byte integer
  127. 8A : 2-bytes integer
  128. 8C : 4-bytes integer
  129. 8E : 8-bytes integer
  130. 90 : single
  131. 92 : double
  132. 94 : decimal
  133. 96 : DateTime
  134. 98 : chars8
  135. 9A : chars16
  136. 9C : chars32
  137. 9E : bytes8 (base64)
  138. A0 : bytes16 (base64 with fixed length?)
  139. A2 : bytes32 (base64)
  140. A4 : TODO: start of list
  141. A6 : TODO: end of list
  142. A8 : empty text
  143. AA : TODO: text index
  144. AC : UniqueId (IsGuid = true)
  145. AE : TimeSpan
  146. B0 : UUID
  147. B2 : UInt64
  148. B4 : bool text
  149. B6 : TODO: unichars8
  150. B8 : TODO: unichars16
  151. BA : TODO: unichars32
  152. BC : TODO: QName index
  153. Error: PIs, doctype
  154. Ignored: XMLdecl
  155. */
  156. }