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 TryFrom<SequencedEvent> for CommitFrame { 42 type Error = &'static str; 43 44 fn try_from(event: SequencedEvent) -> Result<Self, Self::Error> { 45 let ops = serde_json::from_value::<Vec<RepoOp>>(event.ops.unwrap_or_default()) 46 .unwrap_or_else(|_| vec![]); 47 48 let commit_cid = event.commit_cid.ok_or("Missing commit_cid in event")?; 49 50 Ok(CommitFrame { 51 seq: event.seq, 52 rebase: false, 53 too_big: false, 54 repo: event.did, 55 commit: commit_cid, 56 prev: event.prev_cid, 57 blocks: Vec::new(), 58 ops, 59 blobs: event.blobs.unwrap_or_default(), 60 time: event.created_at.to_rfc3339(), 61 }) 62 } 63}