Add command method to NetworkMessage

Also make the return type an &'static str
This commit is contained in:
Steven Roose 2019-12-03 21:19:44 +00:00
parent 854718219e
commit bac3e0308b
No known key found for this signature in database
GPG Key ID: 2F2A88D7F8D68E87
1 changed files with 12 additions and 5 deletions

View File

@ -136,10 +136,10 @@ pub enum NetworkMessage {
Reject(message_network::Reject)
}
impl RawNetworkMessage {
impl NetworkMessage {
/// Return the message command. This is useful for debug outputs.
pub fn command(&self) -> String {
match self.payload {
pub fn command(&self) -> &'static str {
match *self {
NetworkMessage::Version(_) => "version",
NetworkMessage::Verack => "verack",
NetworkMessage::Addr(_) => "addr",
@ -164,7 +164,14 @@ impl RawNetworkMessage {
NetworkMessage::CFCheckpt(_) => "cfcheckpt",
NetworkMessage::Alert(_) => "alert",
NetworkMessage::Reject(_) => "reject",
}.to_owned()
}
}
}
impl RawNetworkMessage {
/// Return the message command. This is useful for debug outputs.
pub fn command(&self) -> &'static str {
self.payload.command()
}
}
@ -193,7 +200,7 @@ impl Encodable for RawNetworkMessage {
) -> Result<usize, encode::Error> {
let mut len = 0;
len += self.magic.consensus_encode(&mut s)?;
len += CommandString(self.command()).consensus_encode(&mut s)?;
len += CommandString(self.command().to_owned()).consensus_encode(&mut s)?;
len += CheckedData(match self.payload {
NetworkMessage::Version(ref dat) => serialize(dat),
NetworkMessage::Addr(ref dat) => serialize(dat),