-
Notifications
You must be signed in to change notification settings - Fork 961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(request-response): add modules for json
and cbor
messages
#3952
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this! I've left some comments with ideas :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good progress! :)
Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I've left some more comments but the direction here looks good! :)
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
I knew should be a better solution to wrap behavior :) |
f732b78
to
74669a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Some final requests and then we can merge this!
json
and cbor
messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thanks for bearing with us on the iterations. I think this is a really nice addition that will make using rust-libp2p
easier :)
json
and cbor
messagesjson
and cbor
messages
Thanks for the review, it is the best way to deep dive into p2p and Rust. |
/// # use libp2p_request_response::{cbor, ProtocolSupport, self as request_response}; | ||
/// # use libp2p_swarm::{StreamProtocol, SwarmBuilder}; | ||
/// #[derive(Debug, serde::Serialize, serde::Deserialize)] | ||
/// struct GreetRequest { | ||
/// name: String, | ||
/// } | ||
/// | ||
/// #[derive(Debug, serde::Serialize, serde::Deserialize)] | ||
/// struct GreetResponse { | ||
/// message: String, | ||
/// } | ||
/// | ||
/// let behaviour = cbor::Behaviour::<GreetRequest, GreetResponse>::new( | ||
/// [(StreamProtocol::new("/my-cbor-protocol"), ProtocolSupport::Full)], | ||
/// request_response::Config::default() | ||
/// ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful how simple this turned out to be. Thanks @dgarus and @thomaseizinger!
This patch adds two modules to `libp2p::request_response`: - `cbor` - `json` Both define a `Behaviour` type-alias that comes with a `Codec` implementation which uses the respective `serde` crate to serialize and deserialize the messages. Fixes libp2p#3905. Pull-Request: libp2p#3952.
…nal cbor impl, remove custom one (See: Remove custom cbor request response implementation, replaced with one from library (See: github.com/libp2p/rust-libp2p/pull/3952)
Description
This patch adds two modules to
libp2p::request_response
:cbor
json
Both define a
Behaviour
type-alias that comes with aCodec
implementation which uses the respectiveserde
crate to serialize and deserialize the messages.Fixes #3905.
Notes & open questions
Behavior
struct to use with theSerdeCodec<Request, Response>
Behavior
with thejson
orcbor
codecChange checklist