1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! The persisted delta document and the keys that name it on the wire.
//!
//! A compacted frame's [`ActivityEventKind::Raw`] value is an object with exactly one key,
//! [`ENVELOPE_DELTA_KEY`], whose value is an [`EnvelopeDelta`]. Requiring the delta to be the
//! *sole* key is what makes detection unambiguous: a provider envelope always carries several
//! top-level fields, so no genuine provider frame can be mistaken for a delta document.
//!
//! [`ActivityEventKind::Raw`]: aion_core::ActivityEventKind::Raw
use ;
use ;
use ;
/// The sole top-level key of a compacted frame's raw value.
///
/// Namespaced to Aion so it cannot collide with a provider field, and checked as the *only* key
/// so a provider frame that happened to carry it alongside its own fields is still treated as a
/// verbatim envelope rather than a delta.
pub const ENVELOPE_DELTA_KEY: &str = "aion_envelope_delta";
/// The delta-document format version this crate writes and reads.
///
/// A reader that meets a higher version reports
/// [`UnresolvedReason::UnsupportedVersion`](super::UnresolvedReason::UnsupportedVersion) rather
/// than guessing at a shape it does not implement.
pub const ENVELOPE_DELTA_VERSION: u64 = 1;
/// One persisted frame expressed as the difference from its turn's base envelope.
/// The lowercase hex SHA-256 of a JSON value's serialized bytes.
///
/// Serialization of a `serde_json::Value` cannot fail for any value that was itself parsed from
/// or built as JSON, but the fallible API is honoured rather than unwrapped: an unserializable
/// value yields `None`, and both the encoder and decoder treat that as "not compactible" /
/// "not resolvable" rather than proceeding on a digest they could not compute.
/// Renders bytes as lowercase hex.
/// Reads the turn identity a provider frame belongs to: its `response.id`.
///
/// A frame without a string `response.id` is not part of a recognisable turn and is left entirely
/// alone by both the encoder and the decoder — it is neither recorded as a base nor compacted.
/// Reads a delta document out of a raw value, or `None` when the value is not one.
///
/// Returns the delta's JSON so the caller can report a malformed document honestly instead of
/// discarding it: a value whose sole key is [`ENVELOPE_DELTA_KEY`] *is* a delta document, whether
/// or not it parses.