Make network-libp2p's Service generic over the message (#1708)

* Make network-libp2p's Service generic over the message

* Apply suggestions from code review

Co-Authored-By: tomaka <pierre.krieger1708@gmail.com>

* Fix warning
This commit is contained in:
Pierre Krieger
2019-02-12 15:36:15 +01:00
committed by Bastian Köcher
parent 1f05a47cdb
commit 9e999cdd81
13 changed files with 262 additions and 224 deletions
+14
View File
@@ -125,6 +125,8 @@ pub struct RemoteReadResponse {
/// Generic types.
pub mod generic {
use parity_codec::{Encode, Decode};
use network_libp2p::CustomMessage;
use runtime_primitives::Justification;
use parity_codec_derive::{Encode, Decode};
use crate::config::Roles;
@@ -197,6 +199,18 @@ pub mod generic {
ChainSpecific(Vec<u8>),
}
impl<Header, Hash, Number, Extrinsic> CustomMessage for Message<Header, Hash, Number, Extrinsic>
where Self: Decode + Encode
{
fn into_bytes(self) -> Vec<u8> {
self.encode()
}
fn from_bytes(bytes: &[u8]) -> Result<Self, ()> {
Decode::decode(&mut &bytes[..]).ok_or(())
}
}
/// Status sent on connection.
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct Status<Hash, Number> {