-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create append entries base types
- Loading branch information
1 parent
1231bb8
commit b133513
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use prost::Message; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
|
||
use super::append_entry::BlockHeader as BH; | ||
use super::append_entry::TransactionExecution as TE; | ||
|
||
#[allow(clippy::large_enum_variant)] | ||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
enum LogEntryData { | ||
BlockHeader(BH), | ||
TransactionExecution(TE), | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
struct LogEntry { | ||
index: u64, | ||
term: u64, | ||
data: LogEntryData, | ||
} | ||
|
||
// Implement Serialize and Deserialize for BH | ||
impl Serialize for BH { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
let bytes = self.encode_to_vec(); | ||
serializer.serialize_bytes(&bytes) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for BH { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
let bytes: Vec<u8> = serde::Deserialize::deserialize(deserializer)?; | ||
BH::decode(&*bytes).map_err(serde::de::Error::custom) | ||
} | ||
} | ||
|
||
// Implement Serialize and Deserialize for TE | ||
impl Serialize for TE { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
let bytes = self.encode_to_vec(); | ||
serializer.serialize_bytes(&bytes) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for TE { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
let bytes: Vec<u8> = serde::Deserialize::deserialize(deserializer)?; | ||
TE::decode(&*bytes).map_err(serde::de::Error::custom) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod append_entries_storage; | ||
pub mod forward_to; | ||
|
||
use std::collections::HashMap; | ||
|