// static methods /// <summary> /// Backpatches the size. /// </summary> /// <param name="stream">The stream.</param> /// <param name="startPosition">The start position.</param> public static void BackpatchSize(this BsonStream stream, long startPosition) { if (stream == null) { throw new ArgumentNullException("stream"); } if (startPosition < 0 || startPosition > stream.Length) { throw new ArgumentOutOfRangeException("startPosition"); } var size = stream.Position - startPosition; if (size > int.MaxValue) { var message = string.Format("Size {0} is larger than {1} (Int32.MaxValue).", size, int.MaxValue); throw new FormatException(message); } var endPosition = stream.Position; stream.Position = startPosition; stream.WriteInt32((int)size); stream.Position = endPosition; }
// static methods /// <summary> /// Backpatches the size. /// </summary> /// <param name="stream">The stream.</param> /// <param name="startPosition">The start position.</param> public static void BackpatchSize(this BsonStream stream, long startPosition) { if (stream == null) { throw new ArgumentNullException("stream"); } if (startPosition < 0 || startPosition > stream.Length) { throw new ArgumentOutOfRangeException("startPosition"); } var endPosition = stream.Position; var size = (int)(endPosition - startPosition); stream.Position = startPosition; stream.WriteInt32(size); stream.Position = endPosition; }
static int _m_WriteInt32(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); MongoDB.Bson.IO.BsonStream gen_to_be_invoked = (MongoDB.Bson.IO.BsonStream)translator.FastGetCSObj(L, 1); { int _value = LuaAPI.xlua_tointeger(L, 2); gen_to_be_invoked.WriteInt32(_value); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary /// <summary> /// Writes BSON binary data to the writer. /// </summary> /// <param name="binaryData">The binary data.</param> public override void WriteBinaryData(BsonBinaryData binaryData) { if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); } if (State != BsonWriterState.Value) { ThrowInvalidState("WriteBinaryData", BsonWriterState.Value); } var bytes = binaryData.Bytes; var subType = binaryData.SubType; var guidRepresentation = binaryData.GuidRepresentation; 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; } _bsonStream.WriteBsonType(BsonType.Binary); WriteNameHelper(); if (subType == BsonBinarySubType.OldBinary) { // sub type OldBinary has two sizes (for historical reasons) _bsonStream.WriteInt32(bytes.Length + 4); _bsonStream.WriteBinarySubType(subType); _bsonStream.WriteInt32(bytes.Length); } else { _bsonStream.WriteInt32(bytes.Length); _bsonStream.WriteBinarySubType(subType); } _bsonStream.WriteBytes(bytes, 0, bytes.Length); State = GetNextState(); }