Fauna v10 .NET/C# Driver 0.2.0-beta
 
Loading...
Searching...
No Matches
Deserializers.cs
Go to the documentation of this file.
1using Fauna.Mapping;
3
4namespace Fauna.Linq;
5
6internal class MappedDeserializer<I, O> : BaseSerializer<O>
7{
8 private ISerializer<I> _inner;
9 private Func<I, O> _mapper;
10
11 public MappedDeserializer(ISerializer<I> inner, Func<I, O> mapper)
12 {
13 _inner = inner;
14 _mapper = mapper;
15 }
16
17 public override O Deserialize(MappingContext context, ref Utf8FaunaReader reader) =>
18 _mapper(_inner.Deserialize(context, ref reader));
19
20 public override void Serialize(MappingContext context, Utf8FaunaWriter writer, object? o)
21 {
22 throw new NotImplementedException();
23 }
24}
25
26internal class ProjectionDeserializer : BaseSerializer<object?[]>
27{
28 private ISerializer[] _fields;
29
30 public ProjectionDeserializer(IEnumerable<ISerializer> fields)
31 {
32 _fields = fields.ToArray();
33 }
34
35 public override object?[] Deserialize(MappingContext context, ref Utf8FaunaReader reader)
36 {
37 if (reader.CurrentTokenType != TokenType.StartArray)
38 throw UnexpectedToken(reader.CurrentTokenType);
39
40 var values = new object?[_fields.Length];
41
42 for (var i = 0; i < _fields.Length; i++)
43 {
44 if (!reader.Read()) throw new SerializationException("Unexpected end of stream");
45 if (reader.CurrentTokenType == TokenType.EndArray) throw UnexpectedToken(reader.CurrentTokenType);
46
47 values[i] = _fields[i].Deserialize(context, ref reader);
48 }
49
50 if (!reader.Read()) throw new SerializationException("Unexpected end of stream");
51 if (reader.CurrentTokenType != TokenType.EndArray) throw UnexpectedToken(reader.CurrentTokenType);
52
53 return values;
54 }
55
56 public override void Serialize(MappingContext context, Utf8FaunaWriter writer, object? o)
57 {
58 throw new NotImplementedException();
59 }
60
61 private new static SerializationException UnexpectedToken(TokenType tokenType) =>
62 new($"Unexpected token while deserializing LINQ element: {tokenType}");
63}
A class representing the mapping context to be used during serialization and deserialization.
Represents error that occur during serialization and deserialization of Fauna data.
Provides functionality for writing data in a streaming manner to a buffer or a stream.
new T Deserialize(MappingContext context, ref Utf8FaunaReader reader)
TokenType
Enumerates the types of tokens used in Fauna serialization.
Definition TokenType.cs:7
Represents a reader that provides fast, non-cached, forward-only access to serialized data.