IBsonWriter.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 writer.
  20. /// </summary>
  21. /// <seealso cref="System.IDisposable" />
  22. public interface IBsonWriter : IDisposable
  23. {
  24. // properties
  25. /// <summary>
  26. /// Gets the position.
  27. /// Not all writers are able to report the position. Those that can't simply return zero.
  28. /// </summary>
  29. /// <value>
  30. /// The position.
  31. /// </value>
  32. long Position { get; }
  33. /// <summary>
  34. /// Gets the current serialization depth.
  35. /// </summary>
  36. int SerializationDepth { get; }
  37. /// <summary>
  38. /// Gets the settings of the writer.
  39. /// </summary>
  40. BsonWriterSettings Settings { get; }
  41. // methods
  42. /// <summary>
  43. /// Gets the current state of the writer.
  44. /// </summary>
  45. BsonWriterState State { get; }
  46. // methods
  47. /// <summary>
  48. /// Closes the writer.
  49. /// </summary>
  50. void Close();
  51. /// <summary>
  52. /// Flushes any pending data to the output destination.
  53. /// </summary>
  54. void Flush();
  55. /// <summary>
  56. /// Pops the element name validator.
  57. /// </summary>
  58. /// <returns>The popped element validator.</returns>
  59. void PopElementNameValidator();
  60. /// <summary>
  61. /// Pops the settings.
  62. /// </summary>
  63. void PopSettings();
  64. /// <summary>
  65. /// Pushes the element name validator.
  66. /// </summary>
  67. /// <param name="validator">The validator.</param>
  68. void PushElementNameValidator(IElementNameValidator validator);
  69. /// <summary>
  70. /// Pushes new settings for the writer.
  71. /// </summary>
  72. /// <param name="configurator">The settings configurator.</param>
  73. void PushSettings(Action<BsonWriterSettings> configurator);
  74. /// <summary>
  75. /// Writes BSON binary data to the writer.
  76. /// </summary>
  77. /// <param name="binaryData">The binary data.</param>
  78. void WriteBinaryData(BsonBinaryData binaryData);
  79. /// <summary>
  80. /// Writes a BSON Boolean to the writer.
  81. /// </summary>
  82. /// <param name="value">The Boolean value.</param>
  83. void WriteBoolean(bool value);
  84. /// <summary>
  85. /// Writes BSON binary data to the writer.
  86. /// </summary>
  87. /// <param name="bytes">The bytes.</param>
  88. void WriteBytes(byte[] bytes);
  89. /// <summary>
  90. /// Writes a BSON DateTime to the writer.
  91. /// </summary>
  92. /// <param name="value">The number of milliseconds since the Unix epoch.</param>
  93. void WriteDateTime(long value);
  94. /// <summary>
  95. /// Writes a BSON Decimal128 to the writer.
  96. /// </summary>
  97. /// <param name="value">The <see cref="Decimal128"/> value.</param>
  98. void WriteDecimal128(Decimal128 value);
  99. /// <summary>
  100. /// Writes a BSON Double to the writer.
  101. /// </summary>
  102. /// <param name="value">The Double value.</param>
  103. void WriteDouble(double value);
  104. /// <summary>
  105. /// Writes the end of a BSON array to the writer.
  106. /// </summary>
  107. void WriteEndArray();
  108. /// <summary>
  109. /// Writes the end of a BSON document to the writer.
  110. /// </summary>
  111. void WriteEndDocument();
  112. /// <summary>
  113. /// Writes a BSON Int32 to the writer.
  114. /// </summary>
  115. /// <param name="value">The Int32 value.</param>
  116. void WriteInt32(int value);
  117. /// <summary>
  118. /// Writes a BSON Int64 to the writer.
  119. /// </summary>
  120. /// <param name="value">The Int64 value.</param>
  121. void WriteInt64(long value);
  122. /// <summary>
  123. /// Writes a BSON JavaScript to the writer.
  124. /// </summary>
  125. /// <param name="code">The JavaScript code.</param>
  126. void WriteJavaScript(string code);
  127. /// <summary>
  128. /// Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).
  129. /// </summary>
  130. /// <param name="code">The JavaScript code.</param>
  131. void WriteJavaScriptWithScope(string code);
  132. /// <summary>
  133. /// Writes a BSON MaxKey to the writer.
  134. /// </summary>
  135. void WriteMaxKey();
  136. /// <summary>
  137. /// Writes a BSON MinKey to the writer.
  138. /// </summary>
  139. void WriteMinKey();
  140. /// <summary>
  141. /// Writes the name of an element to the writer.
  142. /// </summary>
  143. /// <param name="name">The name of the element.</param>
  144. void WriteName(string name);
  145. /// <summary>
  146. /// Writes a BSON null to the writer.
  147. /// </summary>
  148. void WriteNull();
  149. /// <summary>
  150. /// Writes a BSON ObjectId to the writer.
  151. /// </summary>
  152. /// <param name="objectId">The ObjectId.</param>
  153. void WriteObjectId(ObjectId objectId);
  154. /// <summary>
  155. /// Writes a raw BSON array.
  156. /// </summary>
  157. /// <param name="slice">The byte buffer containing the raw BSON array.</param>
  158. void WriteRawBsonArray(IByteBuffer slice);
  159. /// <summary>
  160. /// Writes a raw BSON document.
  161. /// </summary>
  162. /// <param name="slice">The byte buffer containing the raw BSON document.</param>
  163. void WriteRawBsonDocument(IByteBuffer slice);
  164. /// <summary>
  165. /// Writes a BSON regular expression to the writer.
  166. /// </summary>
  167. /// <param name="regex">A BsonRegularExpression.</param>
  168. void WriteRegularExpression(BsonRegularExpression regex);
  169. /// <summary>
  170. /// Writes the start of a BSON array to the writer.
  171. /// </summary>
  172. void WriteStartArray();
  173. /// <summary>
  174. /// Writes the start of a BSON document to the writer.
  175. /// </summary>
  176. void WriteStartDocument();
  177. /// <summary>
  178. /// Writes a BSON String to the writer.
  179. /// </summary>
  180. /// <param name="value">The String value.</param>
  181. void WriteString(string value);
  182. /// <summary>
  183. /// Writes a BSON Symbol to the writer.
  184. /// </summary>
  185. /// <param name="value">The symbol.</param>
  186. void WriteSymbol(string value);
  187. /// <summary>
  188. /// Writes a BSON timestamp to the writer.
  189. /// </summary>
  190. /// <param name="value">The combined timestamp/increment value.</param>
  191. void WriteTimestamp(long value);
  192. /// <summary>
  193. /// Writes a BSON undefined to the writer.
  194. /// </summary>
  195. void WriteUndefined();
  196. }
  197. }