private static void ReadRaw(JsonObject jsonObject, ref BinaryDataReader reader) { int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { var t = reader.ReadNext(); if (t != ExportedDataTypes.asciiString) { throw new FormatException("Expected property name string"); } string propertyName = reader.ReadAsciiString(); if (string.IsNullOrEmpty(propertyName)) { throw new FormatException("Property name string must have a value"); } jsonObject[propertyName] = ReadValue(ref reader); } }
private static JsonValue ReadValue(ref BinaryDataReader reader) { var t = reader.ReadNext(); switch (t) { case ExportedDataTypes.@int: return(reader.ReadInt32()); case ExportedDataTypes.asciiString: return(reader.ReadAsciiString()); case ExportedDataTypes.@string: return(reader.ReadString()); case ExportedDataTypes.utf8String: return(reader.ReadUtf8String()); case ExportedDataTypes.@bool: return(reader.ReadBool()); case ExportedDataTypes.@byte: return(reader.ReadByte()); case ExportedDataTypes.@short: return(reader.ReadInt16()); case ExportedDataTypes.@ushort: return(reader.ReadUInt16()); case ExportedDataTypes.@uint: return(reader.ReadUInt32()); case ExportedDataTypes.@long: return(reader.ReadInt64()); case ExportedDataTypes.@ulong: return(reader.ReadUInt64()); case ExportedDataTypes.@float: return(reader.ReadSingle()); case ExportedDataTypes.@double: return(reader.ReadDouble()); case ExportedDataTypes.@decimal: return(reader.ReadDecimal()); case ExportedDataTypes.dateTime: return(reader.ReadDate()); case ExportedDataTypes.@guid: return(reader.ReadGuid()); case ExportedDataTypes.@null: return(null); case ExportedDataTypes.@object: JsonObject j = new JsonObject(); ReadRaw(j, ref reader); return(j); case ExportedDataTypes.@array: JsonArray a = new JsonArray(); ReadArrayRaw(a, ref reader); return(a); case ExportedDataTypes.byteArray: default: throw new FormatException($"Not supported ExportedDataType {t}"); } }