using System.Text.Json; namespace Discord.Serialization.Json.Converters { internal class UInt8PropertyConverter : IJsonPropertyConverter { public byte Read(JsonReader reader, bool read = true) { if (read) reader.Read(); if (reader.ValueType != JsonValueType.Number) throw new SerializationException("Bad input, expected Number"); return reader.ParseUInt8(); } public void Write(JsonWriter writer, byte value) => writer.WriteValue(value); } internal class UInt16PropertyConverter : IJsonPropertyConverter { public ushort Read(JsonReader reader, bool read = true) { if (read) reader.Read(); if (reader.ValueType != JsonValueType.Number) throw new SerializationException("Bad input, expected Number"); return reader.ParseUInt16(); } public void Write(JsonWriter writer, ushort value) => writer.WriteValue(value); } internal class UInt32PropertyConverter : IJsonPropertyConverter { public uint Read(JsonReader reader, bool read = true) { if (read) reader.Read(); if (reader.ValueType != JsonValueType.Number) throw new SerializationException("Bad input, expected Number"); return reader.ParseUInt32(); } public void Write(JsonWriter writer, uint value) => writer.WriteValue(value); } internal class UInt64PropertyConverter : IJsonPropertyConverter { public ulong Read(JsonReader reader, bool read = true) { if (read) reader.Read(); if (reader.ValueType != JsonValueType.String) throw new SerializationException("Bad input, expected String"); return reader.ParseUInt64(); } public void Write(JsonWriter writer, ulong value) => writer.WriteValue(value.ToString()); } }