XmlBinaryFormat.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 ElemString = 0x40;
  47. public const byte ElemStringPrefix = 0x41;
  48. public const byte ElemIndex = 0x42;
  49. public const byte ElemIndexPrefix = 0x43;
  50. public const byte Zero = 0x80;
  51. public const byte One = 0x82;
  52. public const byte BoolFalse = 0x84;
  53. public const byte BoolTrue = 0x86;
  54. public const byte Int8 = 0x88;
  55. public const byte Int16 = 0x8A;
  56. public const byte Int32 = 0x8C;
  57. public const byte Int64 = 0x8E;
  58. public const byte Single = 0x90;
  59. public const byte Double = 0x92;
  60. public const byte Decimal = 0x94;
  61. public const byte DateTime = 0x96;
  62. public const byte Base64 = 0x9E;
  63. public const byte Base64Fixed = 0xA0;
  64. public const byte Text = 0x98;
  65. public const byte EmptyText = 0xA8;
  66. public const byte UniqueIdFromGuid = 0xAC;
  67. public const byte TimeSpan = 0xAE;
  68. public const byte Guid = 0xB0;
  69. }
  70. /* Binary Format (incomplete):
  71. Literal strings are represented as UTF-8 string, with a length
  72. prefixed to the string itself.
  73. Key indices are based on the rules below:
  74. - dictionary strings which can be found in IXmlDictionary are
  75. doubled its Key. e.g. if the string.Key is 4, then the
  76. output is 8.
  77. - dictionary strings which cannot be found in IXmlDictionary
  78. are stored in the XmlBinaryWriterSession, and its output
  79. number is doubled + 1 e.g. if the string is the first
  80. non-dictionary entry, then the output is 1, and 7 for the
  81. fourth one.
  82. - When the index goes beyond 128, then it becomes 2 bytes,
  83. where the first byte becomes 0x80 + idx % 0x80 and
  84. the second byte becomes idx / 0x80.
  85. Below are operations. Prefixes are always raw strings.
  86. $string is length-prefixed string. @index is index as
  87. described above. [value] is length-prefixed raw array.
  88. 01 : EndElement
  89. 02 $value : Comment
  90. 04 $name : local attribute by string
  91. 05 $prefix $name : global attribute by string
  92. 06 @name : local attribute by index
  93. 07 $prefix @name : global attribute by index
  94. 08 $name : default namespace by string
  95. 09 $prefix $name : prefixed namespace by string
  96. 0A @name : default namespace by index
  97. 0B $prefix @name : prefixed namespace by index
  98. 0C @name : global attribute by index
  99. 0D @name : global attribute by index,
  100. : in current element's namespace
  101. 40 $name : element w/o namespace by string
  102. 41 $prefix $name : element with namespace by string
  103. 42 @name : element w/o namespace by index
  104. 43 $prefix @name : element with namespace by index
  105. 98 $value : text/cdata/chars
  106. 99 $value : text/cdata/chars + EndElement
  107. FIXME: Below are not implemented:
  108. (Uri is simply 98, QName is 98 '{' ns '}' 98 name)
  109. Combined EndElement for below are supported:
  110. 80 : 0 (integer)
  111. 82 : 1 (integer)
  112. 84 : false (bool)
  113. 86 : true (bool)
  114. 88 : 1-byte integer
  115. 8A : 2-bytes integer
  116. 8C : 4-bytes integer
  117. 8E : 8-bytes integer
  118. 90 : single
  119. 92 : double
  120. 94 : decimal
  121. 96 : DateTime
  122. 98 : UniqueId
  123. 9E : base64Binary
  124. A0 : base64Binary fixed length?
  125. AC : UniqueId whose IsGuid = true
  126. AE : TimeSpan
  127. B0 : Guid
  128. Error: PIs, doctype
  129. Ignored: XMLdecl
  130. */
  131. }