sos_protocol/bindings/
patch.rs1include!(concat!(env!("OUT_DIR"), "/patch.rs"));
2
3use crate::{Error, ProtoBinding, Result};
4use sos_core::{
5 commit::{CommitHash, CommitProof},
6 events::{patch::CheckedPatch, EventLogType, EventRecord},
7};
8
9#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct PatchRequest {
15 pub log_type: EventLogType,
17 pub commit: Option<CommitHash>,
20 pub proof: CommitProof,
23 pub patch: Vec<EventRecord>,
25}
26
27impl ProtoBinding for PatchRequest {
28 type Inner = WirePatchRequest;
29}
30
31impl TryFrom<WirePatchRequest> for PatchRequest {
32 type Error = Error;
33
34 fn try_from(value: WirePatchRequest) -> Result<Self> {
35 let commit = if let Some(commit) = value.commit {
36 Some(commit.try_into()?)
37 } else {
38 None
39 };
40
41 let mut patch = Vec::with_capacity(value.patch.len());
42 for event in value.patch {
43 patch.push(event.try_into()?);
44 }
45
46 Ok(Self {
47 log_type: value.log_type.unwrap().try_into()?,
48 commit,
49 proof: value.proof.unwrap().try_into()?,
50 patch,
51 })
52 }
53}
54
55impl From<PatchRequest> for WirePatchRequest {
56 fn from(value: PatchRequest) -> WirePatchRequest {
57 Self {
58 log_type: Some(value.log_type.into()),
59 commit: value.commit.map(|c| c.into()),
60 proof: Some(value.proof.into()),
61 patch: value.patch.into_iter().map(|e| e.into()).collect(),
62 }
63 }
64}
65
66#[derive(Debug, Clone, PartialEq, Eq)]
68pub struct PatchResponse {
69 pub checked_patch: CheckedPatch,
71}
72
73impl ProtoBinding for PatchResponse {
74 type Inner = WirePatchResponse;
75}
76
77impl TryFrom<WirePatchResponse> for PatchResponse {
78 type Error = Error;
79
80 fn try_from(value: WirePatchResponse) -> Result<Self> {
81 Ok(Self {
82 checked_patch: value.checked_patch.unwrap().try_into()?,
83 })
84 }
85}
86
87impl From<PatchResponse> for WirePatchResponse {
88 fn from(value: PatchResponse) -> WirePatchResponse {
89 Self {
90 checked_patch: Some(value.checked_patch.into()),
91 }
92 }
93}