private void ReadValue(Kv1BinaryNodeType type) { var name = Encoding.UTF8.GetString(ReadNullTerminatedBytes()); KvValue value; switch (type) { case Kv1BinaryNodeType.ChildObject: _listener.OnObjectStart(name); ReadObjectCore(); _listener.OnObjectEnd(); return; case Kv1BinaryNodeType.String: // UTF8 encoding is used for string values value = new KvObjectValue <string>(Encoding.UTF8.GetString(ReadNullTerminatedBytes()), KvValueType.String); break; case Kv1BinaryNodeType.WideString: throw new NotSupportedException("Wide String is not supported."); case Kv1BinaryNodeType.Int32: case Kv1BinaryNodeType.Color: case Kv1BinaryNodeType.Pointer: value = new KvObjectValue <int>(_reader.ReadInt32(), KvValueType.Int32); break; case Kv1BinaryNodeType.UInt64: value = new KvObjectValue <ulong>(_reader.ReadUInt64(), KvValueType.UInt64); break; case Kv1BinaryNodeType.Float32: var floatValue = BitConverter.ToSingle(_reader.ReadBytes(4), 0); value = new KvObjectValue <float>(floatValue, KvValueType.FloatingPoint); break; case Kv1BinaryNodeType.Int64: value = new KvObjectValue <long>(_reader.ReadInt64(), KvValueType.Int64); break; default: throw new ArgumentOutOfRangeException(nameof(type)); } _listener.OnKeyValuePair(name, value); }
private void Write(Kv1BinaryNodeType nodeType) { _writer.Write((byte)nodeType); }