Example #1
0
        private void Write(DEncodeDictionary value)
        {
            _writer.Write((byte)'D');
            EncodeVariableLengthInteger((ulong)value.Items.Count);

            foreach (var item in value.Items)
            {
                // write string key
                byte[] buffer = Encoding.UTF8.GetBytes(item.Key);
                EncodeVariableLengthInteger((ulong)buffer.Length);
                _writer.Write(buffer);

                // write value
                Write(item.Value);
            }
        }
Example #2
0
        private DEncodeValue ReadDictionary()
        {
            var count = (int)DecodeVariableLengthInteger();

            var result = new DEncodeDictionary();

            for (int i = 0; i < count; i++)
            {
                var keyBuffer = _reader.ReadBytes((int)DecodeVariableLengthInteger());
                var value = Read();

                result.Items.Add(Encoding.UTF8.GetString(keyBuffer), value);
            }

            return result;
        }