FromBytes() public static method

public static FromBytes ( byte bytes ) : Value
bytes byte
return Value
示例#1
0
        public IEnumerable <KeyValuePair <Key, Value> > Enumerate()
        {
            byte[] key   = null;
            byte[] value = null;
            bool   data  = true;

            while (data)
            {
                try {
                    int keyLen = _reader.Read7BitEncodedInt();
                    if (keyLen < 0 || keyLen > Config.MaxSmallValueSize)
                    {
                        throw new InvalidOperationException("Key length is out of range.");
                    }
                    key = _reader.ReadBytes(keyLen);
                    if (key.Length != keyLen)
                    {
                        throw new InvalidOperationException();
                    }
                    int valueLen = _reader.Read7BitEncodedInt();
                    if (valueLen <= 0)
                    {
                        throw new InvalidOperationException("Value length must be greater than 0.");
                    }
                    value = _reader.ReadBytes(valueLen);
                    if (valueLen != value.Length)
                    {
                        throw new InvalidOperationException("Value length does not match expected data length.");
                    }
                } catch (EndOfStreamException) {
                    data = false;
                } catch (InvalidOperationException) {
                    data = false;
                } catch {
                    data = false;
                }
                if (data)
                {
                    yield return(new KeyValuePair <Key, Value>(Key.FromBytes(key), Value.FromBytes(value)));
                }
            }
        }
示例#2
0
文件: Value.cs 项目: lanicon/razordb
 public static Value Random(int numBytes)
 {
     return(Value.FromBytes(ByteArray.Random(numBytes).InternalBytes));
 }