BsonStream.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. using System.Collections.Generic;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. namespace MongoDB.Bson.IO
  22. {
  23. /// <summary>
  24. /// Represents a Stream has additional methods to suport reading and writing BSON values.
  25. /// </summary>
  26. public abstract class BsonStream : Stream
  27. {
  28. /// <summary>
  29. /// Reads a BSON CString from the stream.
  30. /// </summary>
  31. /// <param name="encoding">The encoding.</param>
  32. /// <returns>A string.</returns>
  33. public abstract string ReadCString(UTF8Encoding encoding);
  34. /// <summary>
  35. /// Reads a BSON CString from the stream.
  36. /// </summary>
  37. /// <returns>An ArraySegment containing the CString bytes (without the null byte).</returns>
  38. public abstract ArraySegment<byte> ReadCStringBytes();
  39. /// <summary>
  40. /// Reads a BSON Decimal128 from the stream.
  41. /// </summary>
  42. /// <returns>A <see cref="Decimal128"/>.</returns>
  43. public abstract Decimal128 ReadDecimal128();
  44. /// <summary>
  45. /// Reads a BSON double from the stream.
  46. /// </summary>
  47. /// <returns>A double.</returns>
  48. public abstract double ReadDouble();
  49. /// <summary>
  50. /// Reads a 32-bit BSON integer from the stream.
  51. /// </summary>
  52. /// <returns>An int.</returns>
  53. public abstract int ReadInt32();
  54. /// <summary>
  55. /// Reads a 64-bit BSON integer from the stream.
  56. /// </summary>
  57. /// <returns>A long.</returns>
  58. public abstract long ReadInt64();
  59. /// <summary>
  60. /// Reads a BSON ObjectId from the stream.
  61. /// </summary>
  62. /// <returns>An ObjectId.</returns>
  63. public abstract ObjectId ReadObjectId();
  64. /// <summary>
  65. /// Reads a raw length prefixed slice from the stream.
  66. /// </summary>
  67. /// <returns>A slice.</returns>
  68. public abstract IByteBuffer ReadSlice();
  69. /// <summary>
  70. /// Reads a BSON string from the stream.
  71. /// </summary>
  72. /// <param name="encoding">The encoding.</param>
  73. /// <returns>A string.</returns>
  74. public abstract string ReadString(UTF8Encoding encoding);
  75. /// <summary>
  76. /// Skips over a BSON CString leaving the stream positioned just after the terminating null byte.
  77. /// </summary>
  78. public abstract void SkipCString();
  79. /// <summary>
  80. /// Writes a BSON CString to the stream.
  81. /// </summary>
  82. /// <param name="value">The value.</param>
  83. public abstract void WriteCString(string value);
  84. /// <summary>
  85. /// Writes the CString bytes to the stream.
  86. /// </summary>
  87. /// <param name="value">The value.</param>
  88. public abstract void WriteCStringBytes(byte[] value);
  89. /// <summary>
  90. /// Writes a BSON Decimal128 to the stream.
  91. /// </summary>
  92. /// <param name="value">The value.</param>
  93. public abstract void WriteDecimal128(Decimal128 value);
  94. /// <summary>
  95. /// Writes a BSON double to the stream.
  96. /// </summary>
  97. /// <param name="value">The value.</param>
  98. public abstract void WriteDouble(double value);
  99. /// <summary>
  100. /// Writes a 32-bit BSON integer to the stream.
  101. /// </summary>
  102. /// <param name="value">The value.</param>
  103. public abstract void WriteInt32(int value);
  104. /// <summary>
  105. /// Writes a 64-bit BSON integer to the stream.
  106. /// </summary>
  107. /// <param name="value">The value.</param>
  108. public abstract void WriteInt64(long value);
  109. /// <summary>
  110. /// Writes a BSON ObjectId to the stream.
  111. /// </summary>
  112. /// <param name="value">The value.</param>
  113. public abstract void WriteObjectId(ObjectId value);
  114. /// <summary>
  115. /// Writes a BSON string to the stream.
  116. /// </summary>
  117. /// <param name="value">The value.</param>
  118. /// <param name="encoding">The encoding.</param>
  119. public abstract void WriteString(string value, UTF8Encoding encoding);
  120. }
  121. }