ICodedInputStream.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. #region Copyright notice and license
  2. // Protocol Buffers - Google's data interchange format
  3. // Copyright 2008 Google Inc. All rights reserved.
  4. // http://github.com/jskeet/dotnet-protobufs/
  5. // Original C++/Java/Python code:
  6. // http://code.google.com/p/protobuf/
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions are
  10. // met:
  11. //
  12. // * Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. // * Redistributions in binary form must reproduce the above
  15. // copyright notice, this list of conditions and the following disclaimer
  16. // in the documentation and/or other materials provided with the
  17. // distribution.
  18. // * Neither the name of Google Inc. nor the names of its
  19. // contributors may be used to endorse or promote products derived from
  20. // this software without specific prior written permission.
  21. //
  22. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. #endregion
  34. using System;
  35. using System.Collections.Generic;
  36. using Google.ProtocolBuffers.Descriptors;
  37. //Disable warning CS3010: CLS-compliant interfaces must have only CLS-compliant members
  38. #pragma warning disable 3010
  39. namespace Google.ProtocolBuffers
  40. {
  41. public interface ICodedInputStream
  42. {
  43. /// <summary>
  44. /// Reads any message initialization data expected from the input stream
  45. /// </summary>
  46. /// <remarks>
  47. /// This is primarily used by text formats and unnecessary for protobuffers' own
  48. /// binary format. The API for MessageStart/End was added for consistent handling
  49. /// of output streams regardless of the actual writer implementation.
  50. /// </remarks>
  51. void ReadMessageStart();
  52. /// <summary>
  53. /// Reads any message finalization data expected from the input stream
  54. /// </summary>
  55. /// <remarks>
  56. /// This is primarily used by text formats and unnecessary for protobuffers' own
  57. /// binary format. The API for MessageStart/End was added for consistent handling
  58. /// of output streams regardless of the actual writer implementation.
  59. /// </remarks>
  60. void ReadMessageEnd();
  61. /// <summary>
  62. /// Attempt to read a field tag, returning false if we have reached the end
  63. /// of the input data.
  64. /// </summary>
  65. /// <remarks>
  66. /// <para>
  67. /// If fieldTag is non-zero and ReadTag returns true then the value in fieldName
  68. /// may or may not be populated. However, if fieldTag is zero and ReadTag returns
  69. /// true, then fieldName should be populated with a non-null field name.
  70. /// </para><para>
  71. /// In other words if ReadTag returns true then either fieldTag will be non-zero OR
  72. /// fieldName will be non-zero. In some cases both may be populated, however the
  73. /// builders will always prefer the fieldTag over fieldName.
  74. /// </para>
  75. /// </remarks>
  76. bool ReadTag(out uint fieldTag, out string fieldName);
  77. /// <summary>
  78. /// Read a double field from the stream.
  79. /// </summary>
  80. bool ReadDouble(ref double value);
  81. /// <summary>
  82. /// Read a float field from the stream.
  83. /// </summary>
  84. bool ReadFloat(ref float value);
  85. /// <summary>
  86. /// Read a uint64 field from the stream.
  87. /// </summary>
  88. bool ReadUInt64(ref ulong value);
  89. /// <summary>
  90. /// Read an int64 field from the stream.
  91. /// </summary>
  92. bool ReadInt64(ref long value);
  93. /// <summary>
  94. /// Read an int32 field from the stream.
  95. /// </summary>
  96. bool ReadInt32(ref int value);
  97. /// <summary>
  98. /// Read a fixed64 field from the stream.
  99. /// </summary>
  100. bool ReadFixed64(ref ulong value);
  101. /// <summary>
  102. /// Read a fixed32 field from the stream.
  103. /// </summary>
  104. bool ReadFixed32(ref uint value);
  105. /// <summary>
  106. /// Read a bool field from the stream.
  107. /// </summary>
  108. bool ReadBool(ref bool value);
  109. /// <summary>
  110. /// Reads a string field from the stream.
  111. /// </summary>
  112. bool ReadString(ref string value);
  113. /// <summary>
  114. /// Reads a group field value from the stream.
  115. /// </summary>
  116. void ReadGroup(int fieldNumber, IBuilderLite builder,
  117. ExtensionRegistry extensionRegistry);
  118. /// <summary>
  119. /// Reads a group field value from the stream and merges it into the given
  120. /// UnknownFieldSet.
  121. /// </summary>
  122. [Obsolete]
  123. void ReadUnknownGroup(int fieldNumber, IBuilderLite builder);
  124. /// <summary>
  125. /// Reads an embedded message field value from the stream.
  126. /// </summary>
  127. void ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry);
  128. /// <summary>
  129. /// Reads a bytes field value from the stream.
  130. /// </summary>
  131. bool ReadBytes(ref ByteString value);
  132. /// <summary>
  133. /// Reads a uint32 field value from the stream.
  134. /// </summary>
  135. bool ReadUInt32(ref uint value);
  136. /// <summary>
  137. /// Reads an enum field value from the stream. The caller is responsible
  138. /// for converting the numeric value to an actual enum.
  139. /// </summary>
  140. bool ReadEnum(ref IEnumLite value, out object unknown, IEnumLiteMap mapping);
  141. /// <summary>
  142. /// Reads an enum field value from the stream. If the enum is valid for type T,
  143. /// then the ref value is set and it returns true. Otherwise the unkown output
  144. /// value is set and this method returns false.
  145. /// </summary>
  146. bool ReadEnum<T>(ref T value, out object unknown)
  147. where T : struct, IComparable, IFormattable;
  148. /// <summary>
  149. /// Reads an sfixed32 field value from the stream.
  150. /// </summary>
  151. bool ReadSFixed32(ref int value);
  152. /// <summary>
  153. /// Reads an sfixed64 field value from the stream.
  154. /// </summary>
  155. bool ReadSFixed64(ref long value);
  156. /// <summary>
  157. /// Reads an sint32 field value from the stream.
  158. /// </summary>
  159. bool ReadSInt32(ref int value);
  160. /// <summary>
  161. /// Reads an sint64 field value from the stream.
  162. /// </summary>
  163. bool ReadSInt64(ref long value);
  164. /// <summary>
  165. /// Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed and the
  166. /// type is numeric, it will read a packed array.
  167. /// </summary>
  168. void ReadPrimitiveArray(FieldType fieldType, uint fieldTag, string fieldName, ICollection<object> list);
  169. /// <summary>
  170. /// Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed, it will
  171. /// read a packed array.
  172. /// </summary>
  173. void ReadEnumArray(uint fieldTag, string fieldName, ICollection<IEnumLite> list, out ICollection<object> unknown,
  174. IEnumLiteMap mapping);
  175. /// <summary>
  176. /// Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed, it will
  177. /// read a packed array.
  178. /// </summary>
  179. void ReadEnumArray<T>(uint fieldTag, string fieldName, ICollection<T> list, out ICollection<object> unknown)
  180. where T : struct, IComparable, IFormattable;
  181. /// <summary>
  182. /// Reads a set of messages using the <paramref name="messageType"/> as a template. T is not guaranteed to be
  183. /// the most derived type, it is only the type specifier for the collection.
  184. /// </summary>
  185. void ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
  186. ExtensionRegistry registry) where T : IMessageLite;
  187. /// <summary>
  188. /// Reads a set of messages using the <paramref name="messageType"/> as a template.
  189. /// </summary>
  190. void ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
  191. ExtensionRegistry registry) where T : IMessageLite;
  192. /// <summary>
  193. /// Reads a field of any primitive type. Enums, groups and embedded
  194. /// messages are not handled by this method.
  195. /// </summary>
  196. bool ReadPrimitiveField(FieldType fieldType, ref object value);
  197. /// <summary>
  198. /// Returns true if the stream has reached the end of the input. This is the
  199. /// case if either the end of the underlying input source has been reached or
  200. /// the stream has reached a limit created using PushLimit.
  201. /// </summary>
  202. bool IsAtEnd { get; }
  203. /// <summary>
  204. /// Reads and discards a single field, given its tag value.
  205. /// </summary>
  206. /// <returns>false if the tag is an end-group tag, in which case
  207. /// nothing is skipped. Otherwise, returns true.</returns>
  208. bool SkipField();
  209. /// <summary>
  210. /// Reads one or more repeated string field values from the stream.
  211. /// </summary>
  212. void ReadStringArray(uint fieldTag, string fieldName, ICollection<string> list);
  213. /// <summary>
  214. /// Reads one or more repeated ByteString field values from the stream.
  215. /// </summary>
  216. void ReadBytesArray(uint fieldTag, string fieldName, ICollection<ByteString> list);
  217. /// <summary>
  218. /// Reads one or more repeated boolean field values from the stream.
  219. /// </summary>
  220. void ReadBoolArray(uint fieldTag, string fieldName, ICollection<bool> list);
  221. /// <summary>
  222. /// Reads one or more repeated Int32 field values from the stream.
  223. /// </summary>
  224. void ReadInt32Array(uint fieldTag, string fieldName, ICollection<int> list);
  225. /// <summary>
  226. /// Reads one or more repeated SInt32 field values from the stream.
  227. /// </summary>
  228. void ReadSInt32Array(uint fieldTag, string fieldName, ICollection<int> list);
  229. /// <summary>
  230. /// Reads one or more repeated UInt32 field values from the stream.
  231. /// </summary>
  232. void ReadUInt32Array(uint fieldTag, string fieldName, ICollection<uint> list);
  233. /// <summary>
  234. /// Reads one or more repeated Fixed32 field values from the stream.
  235. /// </summary>
  236. void ReadFixed32Array(uint fieldTag, string fieldName, ICollection<uint> list);
  237. /// <summary>
  238. /// Reads one or more repeated SFixed32 field values from the stream.
  239. /// </summary>
  240. void ReadSFixed32Array(uint fieldTag, string fieldName, ICollection<int> list);
  241. /// <summary>
  242. /// Reads one or more repeated Int64 field values from the stream.
  243. /// </summary>
  244. void ReadInt64Array(uint fieldTag, string fieldName, ICollection<long> list);
  245. /// <summary>
  246. /// Reads one or more repeated SInt64 field values from the stream.
  247. /// </summary>
  248. void ReadSInt64Array(uint fieldTag, string fieldName, ICollection<long> list);
  249. /// <summary>
  250. /// Reads one or more repeated UInt64 field values from the stream.
  251. /// </summary>
  252. void ReadUInt64Array(uint fieldTag, string fieldName, ICollection<ulong> list);
  253. /// <summary>
  254. /// Reads one or more repeated Fixed64 field values from the stream.
  255. /// </summary>
  256. void ReadFixed64Array(uint fieldTag, string fieldName, ICollection<ulong> list);
  257. /// <summary>
  258. /// Reads one or more repeated SFixed64 field values from the stream.
  259. /// </summary>
  260. void ReadSFixed64Array(uint fieldTag, string fieldName, ICollection<long> list);
  261. /// <summary>
  262. /// Reads one or more repeated Double field values from the stream.
  263. /// </summary>
  264. void ReadDoubleArray(uint fieldTag, string fieldName, ICollection<double> list);
  265. /// <summary>
  266. /// Reads one or more repeated Float field values from the stream.
  267. /// </summary>
  268. void ReadFloatArray(uint fieldTag, string fieldName, ICollection<float> list);
  269. }
  270. }