Пример #1
0
        internal void WriteAsBSONCore(Stream stream)
        {
            var docSize = this.GetByteSize(false);//gets cached value

            BinUtils.WriteInt32(stream, docSize);
            var cnt = m_List.Count;

            for (var i = 0; i < cnt; i++)
            {
                var elm = m_List[i];
                elm.WriteToStream(stream);
            }
            BinUtils.WriteTerminator(stream); //x00
        }
Пример #2
0
        public BSONObjectID(uint epochSeconds, uint machineId, ushort processId, uint counter)
        {
            if (machineId >= THREE_BYTES_UINT_THRESHOLD || counter >= THREE_BYTES_UINT_THRESHOLD)
            {
                throw new BSONException(StringConsts.BSON_THREE_BYTES_UINT_ERROR.Args("machineId and counter") + "  BSONObjectID.ctor(machineId>=2^24 | counter>=2^24)");
            }

            var bytes = new byte[DATA_LENGTH];

            BinUtils.WriteUInt32(bytes, epochSeconds);
            BinUtils.WriteUInt24(bytes, machineId, 4);
            BinUtils.WriteUInt16(bytes, processId, 7);
            BinUtils.WriteUInt24(bytes, counter, 9);
            Bytes = bytes;
        }
Пример #3
0
        protected internal override void WriteValueToStream(Stream stream)
        {
            //Arrays are written as surrogated documents
            var valueSize = getValueByteSize(false);

            BinUtils.WriteInt32(stream, valueSize);
            for (int i = 0; i < Value.Length; i++)
            {
                var element = Value[i];
                BinUtils.WriteByte(stream, (byte)element.ElementType);
                BinUtils.WriteCString(stream, i.ToString(CultureInfo.InvariantCulture));
                element.WriteValueToStream(stream);
            }
            BinUtils.WriteTerminator(stream);
        }
Пример #4
0
        protected override void ReadValueFromStream(Stream stream)
        {
            var flag = BinUtils.ReadByte(stream);

            switch (flag)
            {
            case (byte)BSONBoolean.True:
                Value = true; break;

            case (byte)BSONBoolean.False:
                Value = false; break;

            default:
                throw new BSONException(StringConsts.BSON_READ_BOOLEAN_ERROR.Args(flag));
            }
        }
Пример #5
0
        private int getValueByteSize(bool recalc)
        {
            if (recalc)
            {
                m_ValueByteSize = 4 + //underlying document int32 size
                                  1;  //underlying document terminator
                for (int i = 0; i < Value.Length; i++)
                {
                    m_ValueByteSize += 1 +                            //type
                                       BinUtils.GetIntDigitCount(i) + //name as UTF8 string size
                                       1 +                            //string terminator
                                       Value[i].GetValueByteSize();
                }
            }

            return(m_ValueByteSize);
        }
Пример #6
0
 /// <summary>
 /// Write element to stream
 /// </summary>
 protected internal void WriteToStream(Stream stream)
 {
     BinUtils.WriteByte(stream, (byte)ElementType);
     BinUtils.WriteCString(stream, Name);
     WriteValueToStream(stream);
 }
Пример #7
0
 protected internal override void WriteValueToStream(Stream stream)
 {
     BinUtils.WriteUInt32(stream, Value.Increment);
     BinUtils.WriteUInt32(stream, Value.EpochSeconds);
 }
Пример #8
0
        protected override void ReadValueFromStream(Stream stream)
        {
            var length = BinUtils.ReadInt32(stream);

            Value = BinUtils.ReadCString(stream, length);
        }
Пример #9
0
 protected internal override void WriteValueToStream(Stream stream)
 {
     BinUtils.WriteInt32(stream, Value.Data.Length);
     BinUtils.WriteByte(stream, (byte)Value.Type);
     BinUtils.WriteBinary(stream, Value.Data);
 }
Пример #10
0
 protected internal override void WriteValueToStream(Stream stream)
 {
     BinUtils.WriteInt64(stream, Value);
 }
Пример #11
0
 protected override void ReadValueFromStream(Stream stream)
 {
     Value = BinUtils.ReadInt64(stream);
 }
Пример #12
0
 protected internal override void WriteValueToStream(Stream stream)
 {
     BinUtils.WriteCString(stream, Value.Pattern ?? string.Empty);
     BinUtils.WriteCString(stream, Value.Options.ToBSONString());
 }
Пример #13
0
        protected internal override void WriteValueToStream(Stream stream)
        {
            var dateValue = Value.ToMillisecondsSinceUnixEpochStart();

            BinUtils.WriteInt64(stream, dateValue);
        }
Пример #14
0
 protected override void ReadValueFromStream(Stream stream)
 {
     Value = BinUtils.ReadInt64(stream).FromMillisecondsSinceUnixEpochStart();
 }
Пример #15
0
        protected internal override void WriteValueToStream(Stream stream)
        {
            var b = Value ? (byte)BSONBoolean.True : (byte)BSONBoolean.False;

            BinUtils.WriteByte(stream, b);
        }