Skip to content

Commit

Permalink
Merge pull request #93 from rustaceanrob/de-11-13
Browse files Browse the repository at this point in the history
  • Loading branch information
nyonson authored Nov 13, 2024
2 parents f7df81f + 0b2091c commit 6d4981d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ impl AsyncProtocolReader {

/// Consume the protocol reader in exchange for the underlying packet decoder.
pub fn decoder(self) -> PacketReader {
return self.packet_reader;
self.packet_reader
}
}

Expand Down Expand Up @@ -1332,7 +1332,7 @@ impl AsyncProtocolWriter {

/// Consume the protocol writer in exchange for the underlying packet encoder.
pub fn encoder(self) -> PacketWriter {
return self.packet_writer;
self.packet_writer
}
}

Expand Down
5 changes: 4 additions & 1 deletion protocol/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ pub use bitcoin::p2p::message::{CommandString, NetworkMessage};
pub enum Error {
Serialize,
Deserialize,
UnknownShortID(u8),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Serialize => write!(f, "Unable to serialize"),
Error::Deserialize => write!(f, "Unable to deserialize"),
Error::UnknownShortID(b) => write!(f, "Unrecognized short ID when deserializing {b}"),
}
}
}
Expand All @@ -36,6 +38,7 @@ impl std::error::Error for Error {
match self {
Error::Serialize => None,
Error::Deserialize => None,
Error::UnknownShortID(_) => None,
}
}
}
Expand Down Expand Up @@ -283,7 +286,7 @@ pub fn deserialize(buffer: &[u8]) -> Result<NetworkMessage, Error> {
)),

// Unsupported short ID.
_ => Err(Error::Deserialize),
unknown => Err(Error::UnknownShortID(unknown)),
}
}

Expand Down

0 comments on commit 6d4981d

Please sign in to comment.