IBsonReader.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /* Copyright 2010-present 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. /// Pops the settings.
  56. /// </summary>
  57. void PopSettings();
  58. /// <summary>
  59. /// Pushes new settings for the reader.
  60. /// </summary>
  61. /// <param name="configurator">The settings configurator.</param>
  62. void PushSettings(Action<BsonReaderSettings> configurator);
  63. /// <summary>
  64. /// Reads BSON binary data from the reader.
  65. /// </summary>
  66. /// <returns>A BsonBinaryData.</returns>
  67. BsonBinaryData ReadBinaryData();
  68. /// <summary>
  69. /// Reads a BSON boolean from the reader.
  70. /// </summary>
  71. /// <returns>A Boolean.</returns>
  72. bool ReadBoolean();
  73. /// <summary>
  74. /// Reads a BsonType from the reader.
  75. /// </summary>
  76. /// <returns>A BsonType.</returns>
  77. BsonType ReadBsonType();
  78. /// <summary>
  79. /// Reads BSON binary data from the reader.
  80. /// </summary>
  81. /// <returns>A byte array.</returns>
  82. byte[] ReadBytes();
  83. /// <summary>
  84. /// Reads a BSON DateTime from the reader.
  85. /// </summary>
  86. /// <returns>The number of milliseconds since the Unix epoch.</returns>
  87. long ReadDateTime();
  88. /// <summary>
  89. /// Reads a BSON Decimal128 from the reader.
  90. /// </summary>
  91. /// <returns>A <see cref="Decimal128" />.</returns>
  92. Decimal128 ReadDecimal128();
  93. /// <summary>
  94. /// Reads a BSON Double from the reader.
  95. /// </summary>
  96. /// <returns>A Double.</returns>
  97. double ReadDouble();
  98. /// <summary>
  99. /// Reads the end of a BSON array from the reader.
  100. /// </summary>
  101. void ReadEndArray();
  102. /// <summary>
  103. /// Reads the end of a BSON document from the reader.
  104. /// </summary>
  105. void ReadEndDocument();
  106. /// <summary>
  107. /// Reads a BSON Int32 from the reader.
  108. /// </summary>
  109. /// <returns>An Int32.</returns>
  110. int ReadInt32();
  111. /// <summary>
  112. /// Reads a BSON Int64 from the reader.
  113. /// </summary>
  114. /// <returns>An Int64.</returns>
  115. long ReadInt64();
  116. /// <summary>
  117. /// Reads a BSON JavaScript from the reader.
  118. /// </summary>
  119. /// <returns>A string.</returns>
  120. string ReadJavaScript();
  121. /// <summary>
  122. /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).
  123. /// </summary>
  124. /// <returns>A string.</returns>
  125. string ReadJavaScriptWithScope();
  126. /// <summary>
  127. /// Reads a BSON MaxKey from the reader.
  128. /// </summary>
  129. void ReadMaxKey();
  130. /// <summary>
  131. /// Reads a BSON MinKey from the reader.
  132. /// </summary>
  133. void ReadMinKey();
  134. /// <summary>
  135. /// Reads the name of an element from the reader (using the provided name decoder).
  136. /// </summary>
  137. /// <param name="nameDecoder">The name decoder.</param>
  138. /// <returns>
  139. /// The name of the element.
  140. /// </returns>
  141. string ReadName(INameDecoder nameDecoder);
  142. /// <summary>
  143. /// Reads a BSON null from the reader.
  144. /// </summary>
  145. void ReadNull();
  146. /// <summary>
  147. /// Reads a BSON ObjectId from the reader.
  148. /// </summary>
  149. /// <returns>An ObjectId.</returns>
  150. ObjectId ReadObjectId();
  151. /// <summary>
  152. /// Reads a raw BSON array.
  153. /// </summary>
  154. /// <returns>The raw BSON array.</returns>
  155. IByteBuffer ReadRawBsonArray();
  156. /// <summary>
  157. /// Reads a raw BSON document.
  158. /// </summary>
  159. /// <returns>The raw BSON document.</returns>
  160. IByteBuffer ReadRawBsonDocument();
  161. /// <summary>
  162. /// Reads a BSON regular expression from the reader.
  163. /// </summary>
  164. /// <returns>A BsonRegularExpression.</returns>
  165. BsonRegularExpression ReadRegularExpression();
  166. /// <summary>
  167. /// Reads the start of a BSON array.
  168. /// </summary>
  169. void ReadStartArray();
  170. /// <summary>
  171. /// Reads the start of a BSON document.
  172. /// </summary>
  173. void ReadStartDocument();
  174. /// <summary>
  175. /// Reads a BSON string from the reader.
  176. /// </summary>
  177. /// <returns>A String.</returns>
  178. string ReadString();
  179. /// <summary>
  180. /// Reads a BSON symbol from the reader.
  181. /// </summary>
  182. /// <returns>A string.</returns>
  183. string ReadSymbol();
  184. /// <summary>
  185. /// Reads a BSON timestamp from the reader.
  186. /// </summary>
  187. /// <returns>The combined timestamp/increment.</returns>
  188. long ReadTimestamp();
  189. /// <summary>
  190. /// Reads a BSON undefined from the reader.
  191. /// </summary>
  192. void ReadUndefined();
  193. /// <summary>
  194. /// Returns the reader to previously bookmarked position and state.
  195. /// </summary>
  196. /// <param name="bookmark">The bookmark.</param>
  197. void ReturnToBookmark(BsonReaderBookmark bookmark);
  198. /// <summary>
  199. /// Skips the name (reader must be positioned on a name).
  200. /// </summary>
  201. void SkipName();
  202. /// <summary>
  203. /// Skips the value (reader must be positioned on a value).
  204. /// </summary>
  205. void SkipValue();
  206. }
  207. }