public byte[] GetLeafValue(BTreeLeaf leaf, Key key) { var reader = new LeafReader(this, leaf); var unpacked = DataConverter.Unpack("^i", reader.Read(4), 0); var numKeys = (int)unpacked[0]; for (int i = 0; i < numKeys; i++) { byte[] curKey = reader.Read(KeySize); int pos; bool success; int length = (int)VLQ.FromFunc(_ => reader.Read(1)[0], ctr => true, out pos, out success); if (!success) { throw new Exception("Could not parse VLQ!"); } byte[] value = reader.Read(length); if (curKey.SequenceEqual(key.TheKey)) { return(value); } } return(null); }
/// <summary> /// Reads a VLQ from the stream /// </summary> /// <returns>A VLQ</returns> public ulong ReadVLQ(out int length, out bool success) { ulong result = VLQ.FromFunc(_ => ReadByte(), ctr => true, out length, out success); if (!success) { return(0); } return(result); }