IBsonWriter.cs 6.5 KB

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