-
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 (#1076)
* chore: create append entries base types * doc: add details of log entries
- Loading branch information
1 parent
24fa599
commit 6b02de4
Showing
4 changed files
with
68 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,65 @@ | ||
/// Holds the log entries that are stored in the Raft log. | ||
/// The log entries are either a BlockHeader or a TransactionExecution. | ||
/// The LogEntry struct is used to store the index and term of the log entry. | ||
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,4 +1,5 @@ | ||
pub mod forward_to; | ||
mod log_entry; | ||
|
||
use std::collections::HashMap; | ||
#[cfg(feature = "kubernetes")] | ||
|