38public class Event<T> where T : notnull
47 public long TxnTime {
get;
private init; }
51 public string Cursor {
get;
private init; } =
null!;
55 public T?
Data {
get;
private init; }
59 public QueryStats
Stats {
get;
private init; }
71 var err = GetError(json);
77 var evt =
new Event<T>
82 Stats = GetStats(json),
83 Data = GetData(json, ctx),
98 var json = JsonSerializer.Deserialize<JsonElement>(body);
100 return From(json, ctx);
103 private static long GetTxnTime(JsonElement json)
105 if (!json.TryGetProperty(LastSeenTxnFieldName, out var elem))
110 return elem.TryGetInt64(out
long i) ? i :
default;
113 private static string GetCursor(JsonElement json)
115 if (!json.TryGetProperty(CursorFieldName, out var elem))
117 throw new InvalidDataException($
"Missing required field: cursor - {json.ToString()}");
120 return elem.Deserialize<
string>()!;
124 private static EventType GetType(JsonElement json)
126 if (!json.TryGetProperty(
"type", out var elem))
128 throw new InvalidDataException($
"Missing required field: type - {json.ToString()}");
131 string? evtType = elem.Deserialize<
string?>();
138 _ =>
throw new InvalidOperationException($
"Unknown event type: {evtType}")
144 private static QueryStats GetStats(JsonElement json)
146 return json.TryGetProperty(StatsFieldName, out var elem) ? elem.Deserialize<QueryStats>() : default;
151 if (!json.TryGetProperty(DataFieldName, out var elem))
159 return Serializer.Generate<T>(ctx).
Deserialize(ctx, ref reader);
162 private static ErrorInfo? GetError(JsonElement json)
164 return json.TryGetProperty(ErrorFieldName, out var elem) ? elem.Deserialize<
ErrorInfo>() : null;
A class representing the mapping context to be used during serialization and deserialization.