Skip to content

Commit c564941

Browse files
committed
Decode trait function takes &self as argument
1 parent 58ffe67 commit c564941

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

crates/fuel-core/src/p2p_test_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use fuel_core_chain_config::{
2525
use fuel_core_p2p::{
2626
codecs::{
2727
request_response::RequestResponseMessageHandler,
28-
unbounded::GossipsubMessageHandler,
28+
gossipsub::GossipsubMessageHandler,
2929
},
3030
network_service::FuelP2PService,
3131
p2p_service::FuelP2PEvent,

crates/services/p2p/src/codecs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub trait Encode<T: ?Sized> {
3737
pub trait Decode<T> {
3838
type Error;
3939
/// Decodes the type `T` from the bytes.
40-
fn decode(bytes: &[u8]) -> Result<T, Self::Error>;
40+
fn decode(&self, bytes: &[u8]) -> Result<T, Self::Error>;
4141
}
4242

4343
impl<'a> Encoder for Cow<'a, [u8]> {

crates/services/p2p/src/codecs/gossipsub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ where
4444
) -> Result<Self::ResponseMessage, io::Error> {
4545
let decoded_response = match gossipsub_tag {
4646
GossipTopicTag::NewTx => {
47-
GossipsubMessage::NewTx(Format::decode(encoded_data)?)
47+
GossipsubMessage::NewTx(self.data_format.decode(encoded_data)?)
4848
}
4949
};
5050

crates/services/p2p/src/codecs/postcard.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl RequestResponseMessageHandler<PostcardDataFormat> {
3030
impl GossipsubMessageHandler<PostcardDataFormat> {
3131
pub fn new() -> Self {
3232
GossipsubMessageHandler {
33-
data_format: PostcardDataFormat,
33+
codec: PostcardDataFormat,
3434
}
3535
}
3636
}
@@ -55,7 +55,7 @@ where
5555
{
5656
type Error = io::Error;
5757

58-
fn decode(bytes: &[u8]) -> Result<T, Self::Error> {
58+
fn decode(&self, bytes: &[u8]) -> Result<T, Self::Error> {
5959
postcard::from_bytes(bytes)
6060
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))
6161
}
@@ -228,7 +228,7 @@ mod tests {
228228
let deserialized_as_v1 =
229229
// We cannot access the codec trait from an old node here,
230230
// so we deserialize directly using the `V1ResponseMessage` type.
231-
<PostcardDataFormat as Decode<V1ResponseMessage>>::decode(&buf).expect("Deserialization as V1ResponseMessage should succeed");
231+
codec.data_format.decode(&buf).expect("Deserialization as V1ResponseMessage should succeed");
232232

233233
// Then
234234
assert!(matches!(

crates/services/p2p/src/codecs/request_response.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868
.take(self.max_response_size as u64)
6969
.read_to_end(&mut response)
7070
.await?;
71-
Format::decode(&response)
71+
self.data_format.decode(&response)
7272
}
7373

7474
async fn read_response<T>(
@@ -87,13 +87,11 @@ where
8787

8888
match protocol {
8989
RequestResponseProtocol::V1 => {
90-
let v1_response =
91-
<Format as Decode<V1ResponseMessage>>::decode(&response)?;
90+
let v1_response: V1ResponseMessage =
91+
self.data_format.decode(&response)?;
9292
Ok(v1_response.into())
9393
}
94-
RequestResponseProtocol::V2 => {
95-
<Format as Decode<V2ResponseMessage>>::decode(&response)
96-
}
94+
RequestResponseProtocol::V2 => self.data_format.decode(&response),
9795
}
9896
}
9997

0 commit comments

Comments
 (0)