Implement `Change::decode`

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-11-24 19:13:34 +01:00
parent 0448441418
commit 7e8af47f59
No known key found for this signature in database
1 changed files with 6 additions and 1 deletions

View File

@ -53,6 +53,11 @@ impl Change {
buf buf
} }
/// Deserialize a change from a byte string.
pub fn decode(bytes: &[u8]) -> Result<Self, serde_json::Error> {
serde_json::from_slice(bytes)
}
} }
/// Change envelope. Carries signed changes. /// Change envelope. Carries signed changes.
@ -472,7 +477,7 @@ mod tests {
let actual: Thread = retrieved let actual: Thread = retrieved
.history() .history()
.traverse(Thread::default(), |mut acc, entry| { .traverse(Thread::default(), |mut acc, entry| {
let change: Change = serde_json::from_slice(entry.contents()).unwrap(); let change = Change::decode(entry.contents()).unwrap();
acc.apply([change]); acc.apply([change]);
ControlFlow::Continue(acc) ControlFlow::Continue(acc)