示例#1
0
文件: Journal.cs 项目: T145/archive
        public IEnumerable <KeyValuePair <Key, Value> > Enumerate()
        {
            byte[] key   = null;
            byte[] value = null;
            bool   data  = true;

            while (data)
            {
                try {
                    int keyLen = _reader.Read7BitEncodedInt();
                    key = _reader.ReadBytes(keyLen);
                    if (key.Length != keyLen)
                    {
                        throw new InvalidOperationException();
                    }
                    int valueLen = _reader.Read7BitEncodedInt();
                    value = _reader.ReadBytes(valueLen);
                    if (valueLen <= 0 || valueLen != value.Length)
                    {
                        throw new InvalidOperationException();
                    }
                } catch (EndOfStreamException) {
                    data = false;
                } catch (InvalidOperationException) {
                    data = false;
                }
                if (data)
                {
                    yield return(new KeyValuePair <Key, Value> (Key.FromBytes(key), Value.FromBytes(value)));
                }
            }
        }
示例#2
0
文件: Value.cs 项目: T145/archive
 public static Value Random(int numBytes)
 {
     return(Value.FromBytes(ByteArray.Random(numBytes).InternalBytes));
 }