static int _m_WriteBytes(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);



                {
                    byte[] _buffer = LuaAPI.lua_tobytes(L, 2);
                    int    _offset = LuaAPI.xlua_tointeger(L, 3);
                    int    _count  = LuaAPI.xlua_tointeger(L, 4);

                    gen_to_be_invoked.WriteBytes(_buffer, _offset, _count);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
        /// <summary>
        /// Writes a slice to the stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="slice">The slice.</param>
        public static void WriteSlice(this BsonStream stream, IByteBuffer slice)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (slice == null)
            {
                throw new ArgumentNullException("slice");
            }

            var position = 0;
            var count    = slice.Length;

            while (count > 0)
            {
                var segment      = slice.AccessBackingBytes(position);
                var partialCount = Math.Min(count, segment.Count);
                stream.WriteBytes(segment.Array, segment.Offset, partialCount);
                position += count;
                count    -= partialCount;
            }
        }
Esempio n. 3
0
#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();
        }