ICodedOutputStream.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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;
  36. using Google.Protobuf.Collections;
  37. using Google.Protobuf.Descriptors;
  38. //Disable warning CS3010: CLS-compliant interfaces must have only CLS-compliant members
  39. #pragma warning disable 3010
  40. namespace Google.Protobuf
  41. {
  42. /// <summary>
  43. /// Provides an interface that is used write a message. Most often proto buffers are written
  44. /// in their binary form by creating a instance via the CodedOutputStream.CreateInstance
  45. /// static factory.
  46. /// </summary>
  47. public interface ICodedOutputStream
  48. {
  49. /// <summary>
  50. /// Writes any message initialization data needed to the output stream
  51. /// </summary>
  52. /// <remarks>
  53. /// This is primarily used by text formats and unnecessary for protobuffers' own
  54. /// binary format. The API for MessageStart/End was added for consistent handling
  55. /// of output streams regardless of the actual writer implementation.
  56. /// </remarks>
  57. void WriteMessageStart();
  58. /// <summary>
  59. /// Writes any message finalization data needed to the output stream
  60. /// </summary>
  61. /// <remarks>
  62. /// This is primarily used by text formats and unnecessary for protobuffers' own
  63. /// binary format. The API for MessageStart/End was added for consistent handling
  64. /// of output streams regardless of the actual writer implementation.
  65. /// </remarks>
  66. void WriteMessageEnd();
  67. /// <summary>
  68. /// Indicates that all temporary buffers be written to the final output.
  69. /// </summary>
  70. void Flush();
  71. /// <summary>
  72. /// Writes a field value, including tag, to the stream.
  73. /// </summary>
  74. void WriteField(FieldType fieldType, int fieldNumber, string fieldName, object value);
  75. /// <summary>
  76. /// Writes a double field value, including tag, to the stream.
  77. /// </summary>
  78. void WriteDouble(int fieldNumber, string fieldName, double value);
  79. /// <summary>
  80. /// Writes a float field value, including tag, to the stream.
  81. /// </summary>
  82. void WriteFloat(int fieldNumber, string fieldName, float value);
  83. /// <summary>
  84. /// Writes a uint64 field value, including tag, to the stream.
  85. /// </summary>
  86. void WriteUInt64(int fieldNumber, string fieldName, ulong value);
  87. /// <summary>
  88. /// Writes an int64 field value, including tag, to the stream.
  89. /// </summary>
  90. void WriteInt64(int fieldNumber, string fieldName, long value);
  91. /// <summary>
  92. /// Writes an int32 field value, including tag, to the stream.
  93. /// </summary>
  94. void WriteInt32(int fieldNumber, string fieldName, int value);
  95. /// <summary>
  96. /// Writes a fixed64 field value, including tag, to the stream.
  97. /// </summary>
  98. void WriteFixed64(int fieldNumber, string fieldName, ulong value);
  99. /// <summary>
  100. /// Writes a fixed32 field value, including tag, to the stream.
  101. /// </summary>
  102. void WriteFixed32(int fieldNumber, string fieldName, uint value);
  103. /// <summary>
  104. /// Writes a bool field value, including tag, to the stream.
  105. /// </summary>
  106. void WriteBool(int fieldNumber, string fieldName, bool value);
  107. /// <summary>
  108. /// Writes a string field value, including tag, to the stream.
  109. /// </summary>
  110. void WriteString(int fieldNumber, string fieldName, string value);
  111. /// <summary>
  112. /// Writes a group field value, including tag, to the stream.
  113. /// </summary>
  114. void WriteGroup(int fieldNumber, string fieldName, IMessage value);
  115. /// <summary>
  116. /// Writes a message field value, including tag, to the stream.
  117. /// </summary>
  118. void WriteMessage(int fieldNumber, string fieldName, IMessage value);
  119. /// <summary>
  120. /// Writes a byte array field value, including tag, to the stream.
  121. /// </summary>
  122. void WriteBytes(int fieldNumber, string fieldName, ByteString value);
  123. /// <summary>
  124. /// Writes a UInt32 field value, including tag, to the stream.
  125. /// </summary>
  126. void WriteUInt32(int fieldNumber, string fieldName, uint value);
  127. /// <summary>
  128. /// Writes an enum field value, including tag, to the stream.
  129. /// </summary>
  130. void WriteEnum<T>(int fieldNumber, string fieldName, T value) where T : struct, IComparable, IFormattable;
  131. /// <summary>
  132. /// Writes a fixed 32-bit field value, including tag, to the stream.
  133. /// </summary>
  134. void WriteSFixed32(int fieldNumber, string fieldName, int value);
  135. /// <summary>
  136. /// Writes a signed fixed 64-bit field value, including tag, to the stream.
  137. /// </summary>
  138. void WriteSFixed64(int fieldNumber, string fieldName, long value);
  139. /// <summary>
  140. /// Writes a signed 32-bit field value, including tag, to the stream.
  141. /// </summary>
  142. void WriteSInt32(int fieldNumber, string fieldName, int value);
  143. /// <summary>
  144. /// Writes a signed 64-bit field value, including tag, to the stream.
  145. /// </summary>
  146. void WriteSInt64(int fieldNumber, string fieldName, long value);
  147. /// <summary>
  148. /// Writes a repeated field value, including tag(s), to the stream.
  149. /// </summary>
  150. void WriteArray(FieldType fieldType, int fieldNumber, string fieldName, IEnumerable list);
  151. /// <summary>
  152. /// Writes a repeated group value, including tag(s), to the stream.
  153. /// </summary>
  154. void WriteGroupArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list)
  155. where T : IMessage;
  156. /// <summary>
  157. /// Writes a repeated message value, including tag(s), to the stream.
  158. /// </summary>
  159. void WriteMessageArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list)
  160. where T : IMessage;
  161. /// <summary>
  162. /// Writes a repeated string value, including tag(s), to the stream.
  163. /// </summary>
  164. void WriteStringArray(int fieldNumber, string fieldName, RepeatedField<string> list);
  165. /// <summary>
  166. /// Writes a repeated ByteString value, including tag(s), to the stream.
  167. /// </summary>
  168. void WriteBytesArray(int fieldNumber, string fieldName, RepeatedField<ByteString> list);
  169. /// <summary>
  170. /// Writes a repeated boolean value, including tag(s), to the stream.
  171. /// </summary>
  172. void WriteBoolArray(int fieldNumber, string fieldName, RepeatedField<bool> list);
  173. /// <summary>
  174. /// Writes a repeated Int32 value, including tag(s), to the stream.
  175. /// </summary>
  176. void WriteInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
  177. /// <summary>
  178. /// Writes a repeated SInt32 value, including tag(s), to the stream.
  179. /// </summary>
  180. void WriteSInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
  181. /// <summary>
  182. /// Writes a repeated UInt32 value, including tag(s), to the stream.
  183. /// </summary>
  184. void WriteUInt32Array(int fieldNumber, string fieldName, RepeatedField<uint> list);
  185. /// <summary>
  186. /// Writes a repeated Fixed32 value, including tag(s), to the stream.
  187. /// </summary>
  188. void WriteFixed32Array(int fieldNumber, string fieldName, RepeatedField<uint> list);
  189. /// <summary>
  190. /// Writes a repeated SFixed32 value, including tag(s), to the stream.
  191. /// </summary>
  192. void WriteSFixed32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
  193. /// <summary>
  194. /// Writes a repeated Int64 value, including tag(s), to the stream.
  195. /// </summary>
  196. void WriteInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
  197. /// <summary>
  198. /// Writes a repeated SInt64 value, including tag(s), to the stream.
  199. /// </summary>
  200. void WriteSInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
  201. /// <summary>
  202. /// Writes a repeated UInt64 value, including tag(s), to the stream.
  203. /// </summary>
  204. void WriteUInt64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list);
  205. /// <summary>
  206. /// Writes a repeated Fixed64 value, including tag(s), to the stream.
  207. /// </summary>
  208. void WriteFixed64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list);
  209. /// <summary>
  210. /// Writes a repeated SFixed64 value, including tag(s), to the stream.
  211. /// </summary>
  212. void WriteSFixed64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
  213. /// <summary>
  214. /// Writes a repeated Double value, including tag(s), to the stream.
  215. /// </summary>
  216. void WriteDoubleArray(int fieldNumber, string fieldName, RepeatedField<double> list);
  217. /// <summary>
  218. /// Writes a repeated Float value, including tag(s), to the stream.
  219. /// </summary>
  220. void WriteFloatArray(int fieldNumber, string fieldName, RepeatedField<float> list);
  221. /// <summary>
  222. /// Writes a repeated enumeration value of type T, including tag(s), to the stream.
  223. /// </summary>
  224. void WriteEnumArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list)
  225. where T : struct, IComparable, IFormattable;
  226. /// <summary>
  227. /// Writes a packed repeated primitive, including tag and length, to the stream.
  228. /// </summary>
  229. void WritePackedArray(FieldType fieldType, int fieldNumber, string fieldName, IEnumerable list);
  230. /// <summary>
  231. /// Writes a packed repeated boolean, including tag and length, to the stream.
  232. /// </summary>
  233. void WritePackedBoolArray(int fieldNumber, string fieldName, RepeatedField<bool> list);
  234. /// <summary>
  235. /// Writes a packed repeated Int32, including tag and length, to the stream.
  236. /// </summary>
  237. void WritePackedInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
  238. /// <summary>
  239. /// Writes a packed repeated SInt32, including tag and length, to the stream.
  240. /// </summary>
  241. void WritePackedSInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
  242. /// <summary>
  243. /// Writes a packed repeated UInt32, including tag and length, to the stream.
  244. /// </summary>
  245. void WritePackedUInt32Array(int fieldNumber, string fieldName, RepeatedField<uint> list);
  246. /// <summary>
  247. /// Writes a packed repeated Fixed32, including tag and length, to the stream.
  248. /// </summary>
  249. void WritePackedFixed32Array(int fieldNumber, string fieldName, RepeatedField<uint> list);
  250. /// <summary>
  251. /// Writes a packed repeated SFixed32, including tag and length, to the stream.
  252. /// </summary>
  253. void WritePackedSFixed32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
  254. /// <summary>
  255. /// Writes a packed repeated Int64, including tag and length, to the stream.
  256. /// </summary>
  257. void WritePackedInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
  258. /// <summary>
  259. /// Writes a packed repeated SInt64, including tag and length, to the stream.
  260. /// </summary>
  261. void WritePackedSInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
  262. /// <summary>
  263. /// Writes a packed repeated UInt64, including tag and length, to the stream.
  264. /// </summary>
  265. void WritePackedUInt64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list);
  266. /// <summary>
  267. /// Writes a packed repeated Fixed64, including tag and length, to the stream.
  268. /// </summary>
  269. void WritePackedFixed64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list);
  270. /// <summary>
  271. /// Writes a packed repeated SFixed64, including tag and length, to the stream.
  272. /// </summary>
  273. void WritePackedSFixed64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
  274. /// <summary>
  275. /// Writes a packed repeated Double, including tag and length, to the stream.
  276. /// </summary>
  277. void WritePackedDoubleArray(int fieldNumber, string fieldName, RepeatedField<double> list);
  278. /// <summary>
  279. /// Writes a packed repeated Float, including tag and length, to the stream.
  280. /// </summary>
  281. void WritePackedFloatArray(int fieldNumber, string fieldName, RepeatedField<float> list);
  282. /// <summary>
  283. /// Writes a packed repeated enumeration of type T, including tag and length, to the stream.
  284. /// </summary>
  285. void WritePackedEnumArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list)
  286. where T : struct, IComparable, IFormattable;
  287. }
  288. }