Пример #1
0
        private static Slice?DecodeEntry(Slice p, out uint shared, out uint non_shared, out uint value_length)
        {
            if (p.Length < 3)
            {
                shared       = 0;
                non_shared   = 0;
                value_length = 0;
                return(null);
            }

            shared       = p[0];
            non_shared   = p[1];
            value_length = p[2];
            if ((shared | non_shared | value_length) < 128)
            {
                // Fast path: all three values are encoded in one byte each
                return(p.NewSlice(3));
            }
            else
            {
                shared       = Coding.DecodeVarint32(p);
                non_shared   = Coding.DecodeVarint32(p);
                value_length = Coding.DecodeVarint32(p);

                if (p.Length < non_shared + value_length)
                {
                    return(null);
                }

                return(p);
            }
        }
Пример #2
0
        private void ReadNewFile(Slice slice)
        {
            var level    = Coding.DecodeVarint32(slice);
            var fileNr   = Coding.DecodeVarint64(slice);
            var fileSize = Coding.DecodeVarint64(slice);
            var smallest = new Key(Coding.DecodeLengthPrefixed(slice));
            var largest  = new Key(Coding.DecodeLengthPrefixed(slice));

            m_files.Add(new TableFile(level, fileNr, fileSize, smallest, largest));
        }
Пример #3
0
        public void Add(Record record)
        {
            var actionDict = new Action <Slice>[]
            {
                Error,
                ReadComparator,
                ReadLogNumber,
                ReadNextFileNumber,
                ReadLastSequence,
                ReadCompactPointer,
                ReadDeletedFiled,
                ReadNewFile,
                Error,
                ReadPrevLogNumber,
            };

            var slice = new Slice(record.Bytes);

            while (slice.Length > 0)
            {
                var type = Coding.DecodeVarint32(slice);
                actionDict[type].Invoke(slice);
            }
        }
Пример #4
0
 private void ReadDeletedFiled(Slice slice)
 {
     var level  = Coding.DecodeVarint32(slice);
     var fileNr = Coding.DecodeVarint64(slice);
 }
Пример #5
0
 private void ReadCompactPointer(Slice slice)
 {
     var level   = Coding.DecodeVarint32(slice);
     var pointer = Coding.DecodeLengthPrefixed(slice);
 }