ICodedInputStream.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. /// Attempt to read a field tag, returning false if we have reached the end
  45. /// of the input data.
  46. /// </summary>
  47. /// <remarks>
  48. /// <para>
  49. /// If fieldTag is non-zero and ReadTag returns true then the value in fieldName
  50. /// may or may not be populated. However, if fieldTag is zero and ReadTag returns
  51. /// true, then fieldName should be populated with a non-null field name.
  52. /// </para><para>
  53. /// In other words if ReadTag returns true then either fieldTag will be non-zero OR
  54. /// fieldName will be non-zero. In some cases both may be populated, however the
  55. /// builders will always prefer the fieldTag over fieldName.
  56. /// </para>
  57. /// </remarks>
  58. [CLSCompliant(false)]
  59. bool ReadTag(out uint fieldTag, out string fieldName);
  60. /// <summary>
  61. /// Read a double field from the stream.
  62. /// </summary>
  63. bool ReadDouble(ref double value);
  64. /// <summary>
  65. /// Read a float field from the stream.
  66. /// </summary>
  67. bool ReadFloat(ref float value);
  68. /// <summary>
  69. /// Read a uint64 field from the stream.
  70. /// </summary>
  71. [CLSCompliant(false)]
  72. bool ReadUInt64(ref ulong value);
  73. /// <summary>
  74. /// Read an int64 field from the stream.
  75. /// </summary>
  76. bool ReadInt64(ref long value);
  77. /// <summary>
  78. /// Read an int32 field from the stream.
  79. /// </summary>
  80. bool ReadInt32(ref int value);
  81. /// <summary>
  82. /// Read a fixed64 field from the stream.
  83. /// </summary>
  84. [CLSCompliant(false)]
  85. bool ReadFixed64(ref ulong value);
  86. /// <summary>
  87. /// Read a fixed32 field from the stream.
  88. /// </summary>
  89. [CLSCompliant(false)]
  90. bool ReadFixed32(ref uint value);
  91. /// <summary>
  92. /// Read a bool field from the stream.
  93. /// </summary>
  94. bool ReadBool(ref bool value);
  95. /// <summary>
  96. /// Reads a string field from the stream.
  97. /// </summary>
  98. bool ReadString(ref string value);
  99. /// <summary>
  100. /// Reads a group field value from the stream.
  101. /// </summary>
  102. void ReadGroup(int fieldNumber, IBuilderLite builder,
  103. ExtensionRegistry extensionRegistry);
  104. /// <summary>
  105. /// Reads a group field value from the stream and merges it into the given
  106. /// UnknownFieldSet.
  107. /// </summary>
  108. [Obsolete]
  109. void ReadUnknownGroup(int fieldNumber, IBuilderLite builder);
  110. /// <summary>
  111. /// Reads an embedded message field value from the stream.
  112. /// </summary>
  113. void ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry);
  114. /// <summary>
  115. /// Reads a bytes field value from the stream.
  116. /// </summary>
  117. bool ReadBytes(ref ByteString value);
  118. /// <summary>
  119. /// Reads a uint32 field value from the stream.
  120. /// </summary>
  121. [CLSCompliant(false)]
  122. bool ReadUInt32(ref uint value);
  123. /// <summary>
  124. /// Reads an enum field value from the stream. The caller is responsible
  125. /// for converting the numeric value to an actual enum.
  126. /// </summary>
  127. bool ReadEnum(ref IEnumLite value, out object unknown, IEnumLiteMap mapping);
  128. /// <summary>
  129. /// Reads an enum field value from the stream. If the enum is valid for type T,
  130. /// then the ref value is set and it returns true. Otherwise the unkown output
  131. /// value is set and this method returns false.
  132. /// </summary>
  133. [CLSCompliant(false)]
  134. bool ReadEnum<T>(ref T value, out object unknown)
  135. where T : struct, IComparable, IFormattable, IConvertible;
  136. /// <summary>
  137. /// Reads an sfixed32 field value from the stream.
  138. /// </summary>
  139. bool ReadSFixed32(ref int value);
  140. /// <summary>
  141. /// Reads an sfixed64 field value from the stream.
  142. /// </summary>
  143. bool ReadSFixed64(ref long value);
  144. /// <summary>
  145. /// Reads an sint32 field value from the stream.
  146. /// </summary>
  147. bool ReadSInt32(ref int value);
  148. /// <summary>
  149. /// Reads an sint64 field value from the stream.
  150. /// </summary>
  151. bool ReadSInt64(ref long value);
  152. /// <summary>
  153. /// Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed and the
  154. /// type is numeric, it will read a packed array.
  155. /// </summary>
  156. [CLSCompliant(false)]
  157. void ReadPrimitiveArray(FieldType fieldType, uint fieldTag, string fieldName, ICollection<object> list);
  158. /// <summary>
  159. /// Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed, it will
  160. /// read a packed array.
  161. /// </summary>
  162. [CLSCompliant(false)]
  163. void ReadEnumArray(uint fieldTag, string fieldName, ICollection<IEnumLite> list, out ICollection<object> unknown,
  164. IEnumLiteMap mapping);
  165. /// <summary>
  166. /// Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed, it will
  167. /// read a packed array.
  168. /// </summary>
  169. [CLSCompliant(false)]
  170. void ReadEnumArray<T>(uint fieldTag, string fieldName, ICollection<T> list, out ICollection<object> unknown)
  171. where T : struct, IComparable, IFormattable, IConvertible;
  172. /// <summary>
  173. /// Reads a set of messages using the <paramref name="messageType"/> as a template. T is not guaranteed to be
  174. /// the most derived type, it is only the type specifier for the collection.
  175. /// </summary>
  176. [CLSCompliant(false)]
  177. void ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
  178. ExtensionRegistry registry) where T : IMessageLite;
  179. /// <summary>
  180. /// Reads a set of messages using the <paramref name="messageType"/> as a template.
  181. /// </summary>
  182. [CLSCompliant(false)]
  183. void ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
  184. ExtensionRegistry registry) where T : IMessageLite;
  185. /// <summary>
  186. /// Reads a field of any primitive type. Enums, groups and embedded
  187. /// messages are not handled by this method.
  188. /// </summary>
  189. bool ReadPrimitiveField(FieldType fieldType, ref object value);
  190. /// <summary>
  191. /// Returns true if the stream has reached the end of the input. This is the
  192. /// case if either the end of the underlying input source has been reached or
  193. /// the stream has reached a limit created using PushLimit.
  194. /// </summary>
  195. bool IsAtEnd { get; }
  196. /// <summary>
  197. /// Reads and discards a single field, given its tag value.
  198. /// </summary>
  199. /// <returns>false if the tag is an end-group tag, in which case
  200. /// nothing is skipped. Otherwise, returns true.</returns>
  201. [CLSCompliant(false)]
  202. bool SkipField();
  203. /// <summary>
  204. /// Reads one or more repeated string field values from the stream.
  205. /// </summary>
  206. [CLSCompliant(false)]
  207. void ReadStringArray(uint fieldTag, string fieldName, ICollection<string> list);
  208. /// <summary>
  209. /// Reads one or more repeated ByteString field values from the stream.
  210. /// </summary>
  211. [CLSCompliant(false)]
  212. void ReadBytesArray(uint fieldTag, string fieldName, ICollection<ByteString> list);
  213. /// <summary>
  214. /// Reads one or more repeated boolean field values from the stream.
  215. /// </summary>
  216. [CLSCompliant(false)]
  217. void ReadBoolArray(uint fieldTag, string fieldName, ICollection<bool> list);
  218. /// <summary>
  219. /// Reads one or more repeated Int32 field values from the stream.
  220. /// </summary>
  221. [CLSCompliant(false)]
  222. void ReadInt32Array(uint fieldTag, string fieldName, ICollection<int> list);
  223. /// <summary>
  224. /// Reads one or more repeated SInt32 field values from the stream.
  225. /// </summary>
  226. [CLSCompliant(false)]
  227. void ReadSInt32Array(uint fieldTag, string fieldName, ICollection<int> list);
  228. /// <summary>
  229. /// Reads one or more repeated UInt32 field values from the stream.
  230. /// </summary>
  231. [CLSCompliant(false)]
  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. [CLSCompliant(false)]
  237. void ReadFixed32Array(uint fieldTag, string fieldName, ICollection<uint> list);
  238. /// <summary>
  239. /// Reads one or more repeated SFixed32 field values from the stream.
  240. /// </summary>
  241. [CLSCompliant(false)]
  242. void ReadSFixed32Array(uint fieldTag, string fieldName, ICollection<int> list);
  243. /// <summary>
  244. /// Reads one or more repeated Int64 field values from the stream.
  245. /// </summary>
  246. [CLSCompliant(false)]
  247. void ReadInt64Array(uint fieldTag, string fieldName, ICollection<long> list);
  248. /// <summary>
  249. /// Reads one or more repeated SInt64 field values from the stream.
  250. /// </summary>
  251. [CLSCompliant(false)]
  252. void ReadSInt64Array(uint fieldTag, string fieldName, ICollection<long> list);
  253. /// <summary>
  254. /// Reads one or more repeated UInt64 field values from the stream.
  255. /// </summary>
  256. [CLSCompliant(false)]
  257. void ReadUInt64Array(uint fieldTag, string fieldName, ICollection<ulong> list);
  258. /// <summary>
  259. /// Reads one or more repeated Fixed64 field values from the stream.
  260. /// </summary>
  261. [CLSCompliant(false)]
  262. void ReadFixed64Array(uint fieldTag, string fieldName, ICollection<ulong> list);
  263. /// <summary>
  264. /// Reads one or more repeated SFixed64 field values from the stream.
  265. /// </summary>
  266. [CLSCompliant(false)]
  267. void ReadSFixed64Array(uint fieldTag, string fieldName, ICollection<long> list);
  268. /// <summary>
  269. /// Reads one or more repeated Double field values from the stream.
  270. /// </summary>
  271. [CLSCompliant(false)]
  272. void ReadDoubleArray(uint fieldTag, string fieldName, ICollection<double> list);
  273. /// <summary>
  274. /// Reads one or more repeated Float field values from the stream.
  275. /// </summary>
  276. [CLSCompliant(false)]
  277. void ReadFloatArray(uint fieldTag, string fieldName, ICollection<float> list);
  278. }
  279. }