// protected methods protected override void WriteBody(BsonBuffer buffer) { buffer.WriteInt32(0); // reserved buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName); buffer.WriteInt32(_numberToReturn); buffer.WriteInt64(_cursorId); }
internal override void WriteHeaderTo(BsonBuffer buffer) { base.WriteHeaderTo(buffer); buffer.WriteInt32(0); // reserved buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName); buffer.WriteInt32(_numberToReturn); }
internal virtual void WriteHeaderTo(BsonBuffer buffer) { buffer.WriteInt32(0); // messageLength will be backpatched later buffer.WriteInt32(_requestId); buffer.WriteInt32(0); // responseTo not used in requests sent by client buffer.WriteInt32((int)_opcode); }
protected void WriteMessageHeaderTo( BsonBuffer buffer ) { buffer.WriteInt32(0); // messageLength will be backpatched later buffer.WriteInt32(requestId); buffer.WriteInt32(0); // responseTo not used in requests sent by client buffer.WriteInt32((int) opcode); }
// protected methods protected override void WriteBody(BsonBuffer buffer) { buffer.WriteInt32(0); // reserved buffer.WriteInt32(_cursorIds.Length); foreach (long cursorId in _cursorIds) { buffer.WriteInt64(cursorId); } }
// protected methods protected override void WriteBody(BsonBuffer buffer) { buffer.WriteInt32((int)_flags); buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName); _firstDocumentStartPosition = buffer.Position; // documents to be added later by calling AddDocument }
/// <summary> /// Writes a raw BSON array. /// </summary> /// <param name="slice">The byte buffer containing the raw BSON array.</param> public virtual void WriteRawBsonArray(IByteBuffer slice) { // overridden in BsonBinaryWriter using (var bsonBuffer = new BsonBuffer()) { BsonArray array; // wrap the array in a fake document so we can deserialize it var arrayLength = slice.Length; var documentLength = arrayLength + 8; bsonBuffer.WriteInt32(documentLength); bsonBuffer.WriteByte((byte)BsonType.Array); bsonBuffer.WriteByte((byte)'x'); bsonBuffer.WriteByte((byte)0); bsonBuffer.ByteBuffer.WriteBytes(slice); bsonBuffer.WriteByte((byte)0); bsonBuffer.Position = 0; using (var bsonReader = new BsonBinaryReader(bsonBuffer, true, BsonBinaryReaderSettings.Defaults)) { bsonReader.ReadStartDocument(); bsonReader.ReadName("x"); array = (BsonArray)BsonArraySerializer.Instance.Deserialize(bsonReader, typeof(BsonArray), null); bsonReader.ReadEndDocument(); } BsonArraySerializer.Instance.Serialize(this, typeof(BsonArray), array, null); } }
// internal methods internal override void WriteBodyTo(BsonBuffer buffer) { buffer.WriteInt32(_cursorIds.Length); foreach (long cursorId in _cursorIds) { buffer.WriteInt64(cursorId); } }
// protected methods protected override void WriteBody(BsonBuffer buffer) { buffer.WriteInt32(0); // reserved buffer.WriteCString(_collectionFullName); buffer.WriteInt32((int)_flags); using (var bsonWriter = new BsonBinaryWriter(buffer, false, WriterSettings)) { if (_query == null) { bsonWriter.WriteStartDocument(); bsonWriter.WriteEndDocument(); } else { BsonSerializer.Serialize(bsonWriter, _query.GetType(), _query, DocumentSerializationOptions.SerializeIdFirstInstance); } } }
// protected methods protected override void WriteBody(BsonBuffer buffer) { buffer.WriteInt32((int)_flags); buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName); buffer.WriteInt32(_numberToSkip); buffer.WriteInt32(_numberToReturn); using (var bsonWriter = new BsonBinaryWriter(buffer, false, WriterSettings)) { if (_query == null) { bsonWriter.WriteStartDocument(); bsonWriter.WriteEndDocument(); } else { BsonSerializer.Serialize(bsonWriter, _query.GetType(), _query, DocumentSerializationOptions.SerializeIdFirstInstance); } if (_fields != null) { BsonSerializer.Serialize(bsonWriter, _fields); } } }
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary /// <summary> /// Writes BSON binary data to the writer. /// </summary> /// <param name="bytes">The binary data.</param> /// <param name="subType">The binary data subtype.</param> /// <param name="guidRepresentation">The representation for Guids.</param> public override void WriteBinaryData( byte[] bytes, BsonBinarySubType subType, GuidRepresentation guidRepresentation // ignored since BSON doesn't have a place to store this ) { if (disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); } if (state != BsonWriterState.Value) { ThrowInvalidState("WriteBinaryData", BsonWriterState.Value); } buffer.WriteByte((byte)BsonType.Binary); WriteNameHelper(); if (subType == BsonBinarySubType.OldBinary && settings.FixOldBinarySubTypeOnOutput) { subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type } if (subType == BsonBinarySubType.OldBinary) { // sub type OldBinary has two sizes (for historical reasons) buffer.WriteInt32(bytes.Length + 4); buffer.WriteByte((byte)subType); buffer.WriteInt32(bytes.Length); } else { buffer.WriteInt32(bytes.Length); buffer.WriteByte((byte)subType); } buffer.WriteBytes(bytes); state = GetNextState(); }
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary /// <summary> /// Writes BSON binary data to the writer. /// </summary> /// <param name="bytes">The binary data.</param> /// <param name="subType">The binary data subtype.</param> public override void WriteBinaryData( byte[] bytes, BsonBinarySubType subType ) { if (disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); } if (state != BsonWriterState.Value) { var message = string.Format("WriteBinaryData cannot be called when State is: {0}", state); throw new InvalidOperationException(message); } buffer.WriteByte((byte)BsonType.Binary); WriteNameHelper(); if (subType == BsonBinarySubType.OldBinary && settings.FixOldBinarySubTypeOnOutput) { subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type } if (subType == BsonBinarySubType.OldBinary) { // sub type OldBinary has two sizes (for historical reasons) buffer.WriteInt32(bytes.Length + 4); buffer.WriteByte((byte)subType); buffer.WriteInt32(bytes.Length); } else { buffer.WriteInt32(bytes.Length); buffer.WriteByte((byte)subType); } buffer.WriteBytes(bytes); state = GetNextState(); }
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary /// <summary> /// Writes BSON binary data to the writer. /// </summary> /// <param name="bytes">The binary data.</param> /// <param name="subType">The binary data subtype.</param> /// <param name="guidRepresentation">The representation for Guids.</param> public override void WriteBinaryData( byte[] bytes, BsonBinarySubType subType, GuidRepresentation guidRepresentation ) { if (disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); } if (state != BsonWriterState.Value) { ThrowInvalidState("WriteBinaryData", BsonWriterState.Value); } switch (subType) { case BsonBinarySubType.OldBinary: if (settings.FixOldBinarySubTypeOnOutput) { subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type } break; case BsonBinarySubType.UuidLegacy: case BsonBinarySubType.UuidStandard: if (settings.GuidRepresentation != GuidRepresentation.Unspecified) { var expectedSubType = (settings.GuidRepresentation == GuidRepresentation.Standard) ? BsonBinarySubType.UuidStandard : BsonBinarySubType.UuidLegacy; if (subType != expectedSubType) { var message = string.Format("The GuidRepresentation for the writer is {0}, which requires the subType argument to be {1}, not {2}.", settings.GuidRepresentation, expectedSubType, subType); throw new BsonSerializationException(message); } if (guidRepresentation != settings.GuidRepresentation) { var message = string.Format("The GuidRepresentation for the writer is {0}, which requires the the guidRepresentation argument to also be {0}, not {1}.", settings.GuidRepresentation, guidRepresentation); throw new BsonSerializationException(message); } } break; } buffer.WriteByte((byte)BsonType.Binary); WriteNameHelper(); if (subType == BsonBinarySubType.OldBinary) { // sub type OldBinary has two sizes (for historical reasons) buffer.WriteInt32(bytes.Length + 4); buffer.WriteByte((byte)subType); buffer.WriteInt32(bytes.Length); } else { buffer.WriteInt32(bytes.Length); buffer.WriteByte((byte)subType); } buffer.WriteBytes(bytes); state = GetNextState(); }
internal override void WriteHeaderTo(BsonBuffer buffer) { _batchStartPosition = buffer.Position; base.WriteHeaderTo(buffer); buffer.WriteInt32((int)_flags); buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName); }
internal override void WriteHeaderTo(BsonBuffer buffer) { if ((_flags & QueryFlags.Exhaust) != 0) { throw new NotSupportedException("The Exhaust QueryFlag is not yet supported."); } base.WriteHeaderTo(buffer); buffer.WriteInt32((int)_flags); buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName); buffer.WriteInt32(_numberToSkip); buffer.WriteInt32(_numberToReturn); }
internal override void WriteHeaderTo(BsonBuffer buffer) { base.WriteHeaderTo(buffer); buffer.WriteInt32(0); // reserved }