IBsonReader.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* Copyright 2010-2016 MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. namespace MongoDB.Bson.IO
  17. {
  18. /// <summary>
  19. /// Represents a BSON reader.
  20. /// </summary>
  21. public interface IBsonReader : IDisposable
  22. {
  23. // properties
  24. /// <summary>
  25. /// Gets the current BsonType.
  26. /// </summary>
  27. BsonType CurrentBsonType { get; }
  28. /// <summary>
  29. /// Gets the current state of the reader.
  30. /// </summary>
  31. BsonReaderState State { get; }
  32. // methods
  33. /// <summary>
  34. /// Closes the reader.
  35. /// </summary>
  36. void Close();
  37. /// <summary>
  38. /// Gets a bookmark to the reader's current position and state.
  39. /// </summary>
  40. /// <returns>A bookmark.</returns>
  41. BsonReaderBookmark GetBookmark();
  42. /// <summary>
  43. /// Gets the current BsonType (calls ReadBsonType if necessary).
  44. /// </summary>
  45. /// <returns>The current BsonType.</returns>
  46. BsonType GetCurrentBsonType();
  47. /// <summary>
  48. /// Determines whether this reader is at end of file.
  49. /// </summary>
  50. /// <returns>
  51. /// Whether this reader is at end of file.
  52. /// </returns>
  53. bool IsAtEndOfFile();
  54. /// <summary>
  55. /// Reads BSON binary data from the reader.
  56. /// </summary>
  57. /// <returns>A BsonBinaryData.</returns>
  58. BsonBinaryData ReadBinaryData();
  59. /// <summary>
  60. /// Reads a BSON boolean from the reader.
  61. /// </summary>
  62. /// <returns>A Boolean.</returns>
  63. bool ReadBoolean();
  64. /// <summary>
  65. /// Reads a BsonType from the reader.
  66. /// </summary>
  67. /// <returns>A BsonType.</returns>
  68. BsonType ReadBsonType();
  69. /// <summary>
  70. /// Reads BSON binary data from the reader.
  71. /// </summary>
  72. /// <returns>A byte array.</returns>
  73. byte[] ReadBytes();
  74. /// <summary>
  75. /// Reads a BSON DateTime from the reader.
  76. /// </summary>
  77. /// <returns>The number of milliseconds since the Unix epoch.</returns>
  78. long ReadDateTime();
  79. /// <summary>
  80. /// Reads a BSON Decimal128 from the reader.
  81. /// </summary>
  82. /// <returns>A <see cref="Decimal128" />.</returns>
  83. Decimal128 ReadDecimal128();
  84. /// <summary>
  85. /// Reads a BSON Double from the reader.
  86. /// </summary>
  87. /// <returns>A Double.</returns>
  88. double ReadDouble();
  89. /// <summary>
  90. /// Reads the end of a BSON array from the reader.
  91. /// </summary>
  92. void ReadEndArray();
  93. /// <summary>
  94. /// Reads the end of a BSON document from the reader.
  95. /// </summary>
  96. void ReadEndDocument();
  97. /// <summary>
  98. /// Reads a BSON Int32 from the reader.
  99. /// </summary>
  100. /// <returns>An Int32.</returns>
  101. int ReadInt32();
  102. /// <summary>
  103. /// Reads a BSON Int64 from the reader.
  104. /// </summary>
  105. /// <returns>An Int64.</returns>
  106. long ReadInt64();
  107. /// <summary>
  108. /// Reads a BSON JavaScript from the reader.
  109. /// </summary>
  110. /// <returns>A string.</returns>
  111. string ReadJavaScript();
  112. /// <summary>
  113. /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).
  114. /// </summary>
  115. /// <returns>A string.</returns>
  116. string ReadJavaScriptWithScope();
  117. /// <summary>
  118. /// Reads a BSON MaxKey from the reader.
  119. /// </summary>
  120. void ReadMaxKey();
  121. /// <summary>
  122. /// Reads a BSON MinKey from the reader.
  123. /// </summary>
  124. void ReadMinKey();
  125. /// <summary>
  126. /// Reads the name of an element from the reader (using the provided name decoder).
  127. /// </summary>
  128. /// <param name="nameDecoder">The name decoder.</param>
  129. /// <returns>
  130. /// The name of the element.
  131. /// </returns>
  132. string ReadName(INameDecoder nameDecoder);
  133. /// <summary>
  134. /// Reads a BSON null from the reader.
  135. /// </summary>
  136. void ReadNull();
  137. /// <summary>
  138. /// Reads a BSON ObjectId from the reader.
  139. /// </summary>
  140. /// <returns>An ObjectId.</returns>
  141. ObjectId ReadObjectId();
  142. /// <summary>
  143. /// Reads a raw BSON array.
  144. /// </summary>
  145. /// <returns>The raw BSON array.</returns>
  146. IByteBuffer ReadRawBsonArray();
  147. /// <summary>
  148. /// Reads a raw BSON document.
  149. /// </summary>
  150. /// <returns>The raw BSON document.</returns>
  151. IByteBuffer ReadRawBsonDocument();
  152. /// <summary>
  153. /// Reads a BSON regular expression from the reader.
  154. /// </summary>
  155. /// <returns>A BsonRegularExpression.</returns>
  156. BsonRegularExpression ReadRegularExpression();
  157. /// <summary>
  158. /// Reads the start of a BSON array.
  159. /// </summary>
  160. void ReadStartArray();
  161. /// <summary>
  162. /// Reads the start of a BSON document.
  163. /// </summary>
  164. void ReadStartDocument();
  165. /// <summary>
  166. /// Reads a BSON string from the reader.
  167. /// </summary>
  168. /// <returns>A String.</returns>
  169. string ReadString();
  170. /// <summary>
  171. /// Reads a BSON symbol from the reader.
  172. /// </summary>
  173. /// <returns>A string.</returns>
  174. string ReadSymbol();
  175. /// <summary>
  176. /// Reads a BSON timestamp from the reader.
  177. /// </summary>
  178. /// <returns>The combined timestamp/increment.</returns>
  179. long ReadTimestamp();
  180. /// <summary>
  181. /// Reads a BSON undefined from the reader.
  182. /// </summary>
  183. void ReadUndefined();
  184. /// <summary>
  185. /// Returns the reader to previously bookmarked position and state.
  186. /// </summary>
  187. /// <param name="bookmark">The bookmark.</param>
  188. void ReturnToBookmark(BsonReaderBookmark bookmark);
  189. /// <summary>
  190. /// Skips the name (reader must be positioned on a name).
  191. /// </summary>
  192. void SkipName();
  193. /// <summary>
  194. /// Skips the value (reader must be positioned on a value).
  195. /// </summary>
  196. void SkipValue();
  197. }
  198. }