7internal class StringSerializer : BaseSerializer<string?>
10 reader.CurrentTokenType
switch
12 TokenType.Null =>
null,
13 TokenType.String => reader.GetString(),
14 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
22 writer.WriteNullValue();
25 writer.WriteStringValue(s);
32 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Null, FaunaType.String };
35internal class ByteSerializer : BaseSerializer<byte>
38 reader.CurrentTokenType
switch
40 TokenType.Int => reader.GetByte(),
41 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
49 writer.WriteNullValue();
52 writer.WriteIntValue(i);
59 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Int, FaunaType.Null };
62internal class BytesSerializer : BaseSerializer<byte[]>
65 reader.CurrentTokenType
switch
67 TokenType.Bytes => reader.GetBytes(),
68 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
76 writer.WriteNullValue();
79 writer.WriteBytesValue(b);
86 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Bytes, FaunaType.Null };
89internal class SByteSerializer : BaseSerializer<sbyte>
92 reader.CurrentTokenType
switch
94 TokenType.Int => reader.GetUnsignedByte(),
95 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
103 writer.WriteNullValue();
106 writer.WriteIntValue(i);
113 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Int, FaunaType.Null };
117internal class ShortSerializer : BaseSerializer<short>
120 reader.CurrentTokenType
switch
122 TokenType.Int => reader.GetShort(),
123 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
131 writer.WriteNullValue();
134 writer.WriteIntValue(i);
141 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Int, FaunaType.Null };
144internal class UShortSerializer : BaseSerializer<ushort>
147 reader.CurrentTokenType
switch
149 TokenType.Int => reader.GetUnsignedShort(),
150 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
158 writer.WriteNullValue();
161 writer.WriteIntValue(i);
168 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Int, FaunaType.Null };
171internal class IntSerializer : BaseSerializer<int>
174 reader.CurrentTokenType
switch
176 TokenType.Int => reader.GetInt(),
177 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
185 writer.WriteNullValue();
188 writer.WriteIntValue(i);
195 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Int, FaunaType.Null };
198internal class UIntSerializer : BaseSerializer<uint>
201 reader.CurrentTokenType
switch
203 TokenType.Int or TokenType.Long => reader.GetUnsignedInt(),
204 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
212 writer.WriteNullValue();
215 writer.WriteLongValue(i);
222 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Int,
FaunaType.Long, FaunaType.Null };
225internal class LongSerializer : BaseSerializer<long>
228 reader.CurrentTokenType
switch
230 TokenType.Int or TokenType.Long => reader.GetLong(),
231 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
239 writer.WriteNullValue();
242 writer.WriteLongValue(i);
249 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Int,
FaunaType.Long, FaunaType.Null };
252internal class FloatSerializer : BaseSerializer<float>
255 reader.CurrentTokenType
switch
257 TokenType.Int or TokenType.Long or TokenType.Double => reader.GetFloat(),
258 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
266 writer.WriteNullValue();
269 writer.WriteDoubleValue(i);
277 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Double,
FaunaType.Int,
FaunaType.Long, FaunaType.Null };
280internal class DoubleSerializer : BaseSerializer<double>
283 reader.CurrentTokenType
switch
285 TokenType.Int or TokenType.Long or TokenType.Double => reader.GetDouble(),
286 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
294 writer.WriteNullValue();
297 writer.WriteDoubleValue(i);
304 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Double,
FaunaType.Int,
FaunaType.Long, FaunaType.Null };
307internal class BooleanSerializer : BaseSerializer<bool>
310 reader.CurrentTokenType
switch
312 TokenType.True or TokenType.False => reader.GetBoolean(),
313 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
321 writer.WriteNullValue();
324 writer.WriteBooleanValue(i);
331 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Boolean, FaunaType.Null };
334internal class DateOnlySerializer : BaseSerializer<DateOnly>
337 reader.CurrentTokenType
switch
339 TokenType.Date => reader.GetDate(),
340 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
348 writer.WriteNullValue();
351 writer.WriteDateValue(i);
358 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Date, FaunaType.Null };
361internal class DateTimeSerializer : BaseSerializer<DateTime>
364 reader.CurrentTokenType
switch
366 TokenType.Time => reader.GetTime(),
367 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
375 writer.WriteNullValue();
378 writer.WriteTimeValue(i);
385 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Null, FaunaType.Time };
388internal class DateTimeOffsetSerializer : BaseSerializer<DateTimeOffset>
391 reader.CurrentTokenType
switch
393 TokenType.Time => reader.GetTime(),
394 _ =>
throw new SerializationException(UnexpectedTypeDecodingMessage(reader.CurrentTokenType.GetFaunaType()))
402 writer.WriteNullValue();
404 case DateTimeOffset i:
405 writer.WriteTimeValue(i);
412 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Null, FaunaType.Time };
Represents error that occur during serialization and deserialization of Fauna data.
A class representing the mapping context to be used during serialization and deserialization.
string UnsupportedSerializationTypeMessage(Type type)
A helper to build an unsupported serialization type exception message.
object? ISerializer. Deserialize(MappingContext ctx, ref Utf8FaunaReader reader)
Consumes or partially consumes the provided reader and deserializes into a result.
void ISerializer. Serialize(MappingContext context, Utf8FaunaWriter writer, object? o)
Serializes the provided object onto the Utf8FaunaWriter
FaunaType
An enum representing possible Fauna types.