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
|
use crate::server::{attrs::Attr, blobref::BlobRef};
use rand::{thread_rng, Rng};
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub(super) struct Anchor {
rand: u64,
#[serde(with = "time::serde::rfc3339")]
created_at: OffsetDateTime,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub(super) struct Patch {
pub anchor: BlobRef,
pub changes: Vec<Change>,
#[serde(with = "time::serde::rfc3339")]
created_at: OffsetDateTime,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
// #[allow(clippy::enum_variant_names)]
pub(super) enum Change {
AddChunk {
blobref: BlobRef,
offset: u64,
size: usize,
},
SetAttr(Attr),
}
impl Anchor {
pub(super) fn new() -> Self {
Self {
rand: thread_rng().gen(),
created_at: OffsetDateTime::now_utc(),
}
}
}
impl Patch {
pub(super) fn new(anchor: BlobRef) -> Self {
Self {
anchor,
changes: Vec::new(),
created_at: OffsetDateTime::now_utc(),
}
}
pub(super) fn add_change(&mut self, change: Change) {
self.changes.push(change);
}
}
|