示例#1
0
        public static Decimal ReadDecimal(this BufferSlice buffer, int offset)
        {
            var a = buffer.ReadInt32(offset);
            var b = buffer.ReadInt32(offset + 4);
            var c = buffer.ReadInt32(offset + 8);
            var d = buffer.ReadInt32(offset + 12);

            return(new Decimal(new int[] { a, b, c, d }));
        }
示例#2
0
        /// <summary>
        /// Read any BsonValue. Use 1 byte for data type, 1 byte for length (optional), 0-255 bytes to value.
        /// For document or array, use BufferReader
        /// </summary>
        public static BsonValue ReadIndexKey(this BufferSlice buffer, int offset)
        {
            ExtendedLengthHelper.ReadLength(buffer[offset++], buffer[offset], out var type, out var len);

            switch (type)
            {
            case BsonType.Null: return(BsonValue.Null);

            case BsonType.Int32: return(buffer.ReadInt32(offset));

            case BsonType.Int64: return(buffer.ReadInt64(offset));

            case BsonType.Double: return(buffer.ReadDouble(offset));

            case BsonType.Decimal: return(buffer.ReadDecimal(offset));

            case BsonType.String:
                offset++;     // for byte length
                return(buffer.ReadString(offset, len));

            case BsonType.Document:
                using (var r = new BufferReader(buffer))
                {
                    r.Skip(offset);     // skip first byte for value.Type
                    return(r.ReadDocument());
                }

            case BsonType.Array:
                using (var r = new BufferReader(buffer))
                {
                    r.Skip(offset);     // skip first byte for value.Type
                    return(r.ReadArray());
                }

            case BsonType.Binary:
                offset++;     // for byte length
                return(buffer.ReadBytes(offset, len));

            case BsonType.ObjectId: return(buffer.ReadObjectId(offset));

            case BsonType.Guid: return(buffer.ReadGuid(offset));

            case BsonType.Boolean: return(buffer[offset] != 0);

            case BsonType.DateTime: return(buffer.ReadDateTime(offset));

            case BsonType.MinValue: return(BsonValue.MinValue);

            case BsonType.MaxValue: return(BsonValue.MaxValue);

            default: throw new NotImplementedException();
            }
        }