Beispiel #1
0
        public static BSONElement GUID_CLRtoBSON(string name, Guid guid)
        {
            if (guid == Guid.Empty)
            {
                return(new BSONNullElement(name));
            }
            //As tested on Feb 27, 2015
            //BinData works faster than string 8% and stores 40%-60% less data in index and data segment
            //Also, SEQUENTIAL keys (big endian) yield 30% smaller indexes (vs non-sequential)
            //ObjectId() is very similar if not identical to BinData(UserDefined)
            var bin = new BSONBinary(BSONBinaryType.UUID, guid.ToNetworkByteOrder());

            return(name != null ?  new BSONBinaryElement(name, bin) : new BSONBinaryElement(bin));
        }
Beispiel #2
0
        public static BSONElement ByteBuffer_CLRtoBSON(string name, byte[] buf)
        {
            if (buf == null)
            {
                return(new BSONNullElement(name));
            }
            if (buf.Length > MAX_BYTE_BUFFER_SIZE)
            {
                throw new BSONException(StringConsts.BUFFER_LONGER_THAN_ALLOWED_ERROR.Args(buf.Length, MAX_BYTE_BUFFER_SIZE));
            }

            var bsonBin = new BSONBinary(BSONBinaryType.GenericBinary, buf);

            return(name != null ? new BSONBinaryElement(name, bsonBin) : new BSONBinaryElement(bsonBin));
        }