Skip to content

Commit

Permalink
Add serde support
Browse files Browse the repository at this point in the history
  • Loading branch information
shekohex committed Jan 17, 2024
1 parent 1b372fe commit 89a2504
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.cargo/

.helix/
.direnv/
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions round-based/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ round-based-derive = { version = "0.2", optional = true }
tokio = { version = "1", features = ["rt"], optional = true }
tokio-stream = { version = "0.1", features = ["sync"], optional = true }

serde = { version = "1", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
trybuild = "1"
matches = "0.1"
Expand All @@ -36,6 +38,7 @@ default = []
dev = ["tokio/sync", "tokio-stream"]
derive = ["round-based-derive"]
runtime-tokio = ["tokio"]
serde = ["dep:serde"]

[[test]]
name = "derive"
Expand Down
4 changes: 4 additions & 0 deletions round-based/src/delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ where

/// Incoming message
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Incoming<M> {
/// Index of a message
pub id: MsgId,
Expand All @@ -52,6 +53,7 @@ pub struct Incoming<M> {

/// Message type (broadcast or p2p)
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MessageType {
/// Message was broadcasted
Broadcast,
Expand Down Expand Up @@ -119,6 +121,7 @@ impl<M> Incoming<M> {

/// Outgoing message
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Outgoing<M> {
/// Message destination: either one party (p2p message) or all parties (broadcast message)
pub recipient: MessageDestination,
Expand Down Expand Up @@ -175,6 +178,7 @@ impl<M> Outgoing<M> {

/// Destination of an outgoing message
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MessageDestination {
/// Broadcast message
AllParties,
Expand Down

0 comments on commit 89a2504

Please sign in to comment.