8internal class RefSerializer<T> :
BaseSerializer<Ref<T>> where T : notnull
10 private readonly BaseRefSerializer<T> _baseRefSerializer;
14 _baseRefSerializer =
new BaseRefSerializer<T>(docSerializer);
17 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Null, FaunaType.Ref };
26 _baseRefSerializer.
Serialize(context, writer, o);
30internal class NamedRefSerializer<T> :
BaseSerializer<NamedRef<T>> where T : notnull
32 private readonly BaseRefSerializer<T> _baseRefSerializer;
34 public NamedRefSerializer(
ISerializer docSerializer)
36 _baseRefSerializer =
new BaseRefSerializer<T>(docSerializer);
39 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Null, FaunaType.Ref };
48 _baseRefSerializer.
Serialize(context, writer, o);
52internal class BaseRefSerializer<T> :
BaseSerializer<BaseRef<T>> where T : notnull
58 _docSerializer = docSerializer;
61 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Null, FaunaType.Ref };
65 return reader.CurrentTokenType
switch
67 TokenType.StartRef => DeserializeRefInternal(
new BaseRefBuilder<T>(), ctx, ref reader),
68 TokenType.StartDocument => DeserializeDocument(
new BaseRefBuilder<T>(), ctx, ref reader),
70 $
"Unexpected token while deserializing into Ref: {reader.CurrentTokenType}")
101 while (reader.Read() && reader.CurrentTokenType !=
TokenType.EndRef)
103 if (reader.CurrentTokenType !=
TokenType.FieldName)
105 $
"Unexpected token while deserializing into NamedRef: {reader.CurrentTokenType}");
107 string fieldName = reader.GetString()!;
112 builder.Id = reader.GetString();
115 builder.Name = reader.GetString();
118 builder.Collection = reader.GetModule();
121 builder.Cause = reader.GetString();
124 builder.Exists = reader.GetBoolean();
128 $
"Unexpected field while deserializing into Ref: {fieldName}");
132 return builder.Build();
138 while (reader.Read() && reader.CurrentTokenType !=
TokenType.EndDocument)
140 if (reader.CurrentTokenType !=
TokenType.FieldName)
142 $
"Unexpected token while deserializing into NamedRef: {reader.CurrentTokenType}");
144 string fieldName = reader.GetString()!;
149 builder.Id = reader.GetString();
152 builder.Name = reader.GetString();
155 builder.Collection = reader.GetModule();
157 if (_docSerializer is not IPartialDocumentSerializer cs)
159 throw new SerializationException($
"Serializer {_docSerializer.GetType().Name} must implement IPartialDocumentSerializer interface.");
163 builder.Doc = (T?)cs.DeserializeDocument(context, builder.Id, builder.Name, builder.Collection, ref reader);
168 if (reader.CurrentTokenType ==
TokenType.EndDocument)
break;
171 return builder.Build();
A class representing the mapping context to be used during serialization and deserialization.
void ISerializer. Serialize(MappingContext context, Utf8FaunaWriter writer, object? o)
Serializes the provided object onto the Utf8FaunaWriter