Example #1
0
        /// <summary>
        /// Reads BSON binary data from the reader.
        /// </summary>
        /// <returns>A BsonBinaryData.</returns>
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
        public override BsonBinaryData ReadBinaryData()
        {
            if (Disposed)
            {
                ThrowObjectDisposedException();
            }
            VerifyBsonType("ReadBinaryData", BsonType.Binary);

            int size = ReadSize();

            var subType = _bsonStream.ReadBinarySubType();

            if (subType == BsonBinarySubType.OldBinary)
            {
                // sub type OldBinary has two sizes (for historical reasons)
                int size2 = ReadSize();
                if (size2 != size - 4)
                {
                    throw new FormatException("Binary sub type OldBinary has inconsistent sizes");
                }
                size = size2;

                if (Settings.FixOldBinarySubTypeOnInput)
                {
                    subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type
                }
            }

            var bytes = _bsonStream.ReadBytes(size);

            BsonBinaryData binaryData;

            if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
            {
                GuidRepresentation guidRepresentation;
                switch (subType)
                {
                case BsonBinarySubType.UuidLegacy: guidRepresentation = Settings.GuidRepresentation; break;

                case BsonBinarySubType.UuidStandard: guidRepresentation = GuidRepresentation.Standard; break;

                default: guidRepresentation = GuidRepresentation.Unspecified; break;
                }
                binaryData = new BsonBinaryData(bytes, subType, guidRepresentation);
            }
            else
            {
                binaryData = new BsonBinaryData(bytes, subType);
            }

            State = GetNextState();
            return(binaryData);
        }
        /// <summary>
        /// Reads BSON binary data from the reader.
        /// </summary>
        /// <returns>A BsonBinaryData.</returns>
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
        public override BsonBinaryData ReadBinaryData()
        {
            if (Disposed)
            {
                ThrowObjectDisposedException();
            }
            VerifyBsonType("ReadBinaryData", BsonType.Binary);

            int size = ReadSize();

            var subType = _bsonStream.ReadBinarySubType();

            if (subType == BsonBinarySubType.OldBinary)
            {
                // sub type OldBinary has two sizes (for historical reasons)
                int size2 = ReadSize();
                if (size2 != size - 4)
                {
                    throw new FormatException("Binary sub type OldBinary has inconsistent sizes");
                }
                size = size2;

                if (_settings.FixOldBinarySubTypeOnInput)
                {
                    subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type
                }
            }

            var bytes = _bsonStream.ReadBytes(size);

            var guidRepresentation = GuidRepresentation.Unspecified;

            if (subType == BsonBinarySubType.UuidLegacy || subType == 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 reader is {0}, which requires the binary sub type to be {1}, not {2}.",
                            _settings.GuidRepresentation, expectedSubType, subType);
                        throw new FormatException(message);
                    }
                }
                guidRepresentation = (subType == BsonBinarySubType.UuidStandard) ? GuidRepresentation.Standard : _settings.GuidRepresentation;
            }

            State = GetNextState();
            return(new BsonBinaryData(bytes, subType, guidRepresentation));
        }
        static int _m_ReadBinarySubType(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);



                {
                    MongoDB.Bson.BsonBinarySubType gen_ret = gen_to_be_invoked.ReadBinarySubType(  );
                    translator.PushMongoDBBsonBsonBinarySubType(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }