void ReadValue(string name, KV2BinaryNodeType type) { KVValue value; switch (type) { case KV2BinaryNodeType.ChildObject: { listener.OnObjectStart(name); do { ReadObjectCore(); }while (PeekNextNodeType() != KV2BinaryNodeType.End); listener.OnObjectEnd(); return; } case KV2BinaryNodeType.String: value = new KVObjectValue <string>(ReadNullTerminatedString(), KVValueType.String); break; case KV2BinaryNodeType.WideString: throw new NotSupportedException("Wide String is not supported."); case KV2BinaryNodeType.Int32: case KV2BinaryNodeType.Color: case KV2BinaryNodeType.Pointer: value = new KVObjectValue <int>(reader.ReadInt32(), KVValueType.Int32); break; case KV2BinaryNodeType.UInt64: value = new KVObjectValue <ulong>(reader.ReadUInt64(), KVValueType.UInt64); break; case KV2BinaryNodeType.Float32: var floatValue = BitConverter.ToSingle(reader.ReadBytes(4), 0); value = new KVObjectValue <float>(floatValue, KVValueType.FloatingPoint); break; default: throw new ArgumentOutOfRangeException(nameof(type)); } listener.OnKeyValuePair(name, value); }
void Write(KV2BinaryNodeType nodeType) { writer.Write((byte)nodeType); }