this repo has no description
1use serde::{Deserialize, Serialize};
2use crate::sync::firehose::SequencedEvent;
3
4#[derive(Debug, Serialize, Deserialize)]
5pub struct Frame {
6 #[serde(rename = "op")]
7 pub op: i64,
8 #[serde(rename = "d")]
9 pub data: FrameData,
10}
11
12#[derive(Debug, Serialize, Deserialize)]
13#[serde(untagged)]
14pub enum FrameData {
15 Commit(Box<CommitFrame>),
16}
17
18#[derive(Debug, Serialize, Deserialize)]
19pub struct CommitFrame {
20 pub seq: i64,
21 pub rebase: bool,
22 #[serde(rename = "tooBig")]
23 pub too_big: bool,
24 pub repo: String,
25 pub commit: String,
26 pub prev: Option<String>,
27 #[serde(with = "serde_bytes")]
28 pub blocks: Vec<u8>,
29 pub ops: Vec<RepoOp>,
30 pub blobs: Vec<String>,
31 pub time: String,
32}
33
34#[derive(Debug, Serialize, Deserialize)]
35pub struct RepoOp {
36 pub action: String,
37 pub path: String,
38 pub cid: Option<String>,
39}
40
41impl From<SequencedEvent> for CommitFrame {
42 fn from(event: SequencedEvent) -> Self {
43 let ops = serde_json::from_value::<Vec<RepoOp>>(event.ops.unwrap_or_default())
44 .unwrap_or_else(|_| vec![]);
45
46 CommitFrame {
47 seq: event.seq,
48 rebase: false,
49 too_big: false,
50 repo: event.did,
51 commit: event.commit_cid.unwrap_or_default(),
52 prev: event.prev_cid,
53 blocks: Vec::new(),
54 ops,
55 blobs: event.blobs.unwrap_or_default(),
56 time: event.created_at.to_rfc3339(),
57 }
58 }
59}