Exemplo n.º 1
0
            public static bool Decode(StringPiece slice, out KeyPrefix prefix)
            {
                if (slice.Empty)
                {
                    prefix = default(KeyPrefix);
                    return(false);
                }

                var firstByte          = slice.Next();
                var databaseIdBytes    = ((firstByte >> 5) & 0x7) + 1;
                var objectStoreIdBytes = ((firstByte >> 2) & 0x7) + 1;
                var indexIdBytes       = (firstByte & 0x3) + 1;

                if (databaseIdBytes + objectStoreIdBytes + indexIdBytes > slice.Left)
                {
                    prefix = default(KeyPrefix);
                    return(false);
                }

                prefix = new KeyPrefix();
                return(slice.Slice(databaseIdBytes).DecodeInt(out prefix.DatabaseId) &&
                       slice.Slice(objectStoreIdBytes).DecodeInt(out prefix.ObjectStoreId) &&
                       slice.Slice(indexIdBytes).DecodeInt(out prefix.IndexId));
            }
Exemplo n.º 2
0
        private static int CompareEncodedStringsWithLength(StringPiece slice1, StringPiece slice2, out bool ok)
        {
            long len1, len2;

            if (!slice1.DecodeVarInt(out len1) || !slice2.DecodeVarInt(out len2) || len1 < 0 || len2 < 0)
            {
                ok = false;
                return(0);
            }

            var size1 = (int)len1 * 2;
            var size2 = (int)len2 * 2;

            if (slice1.Left < size1 || slice2.Left < size2)
            {
                ok = false;
                return(0);
            }

            // Extract the binary data, and advance the passed slices.
            ok = true;
            return(slice1.Slice(size1).CompareTo(slice2.Slice(size2)));
        }