feat(request-response): add modules for json and cbor messages#3952
feat(request-response): add modules for json and cbor messages#3952mergify[bot] merged 45 commits intolibp2p:masterfrom dgarus:3905-serde_support
json and cbor messages#3952Conversation
thomaseizinger
left a comment
There was a problem hiding this comment.
Thanks for tackling this! I've left some comments with ideas :)
thomaseizinger
left a comment
There was a problem hiding this comment.
Good progress! :)
Thanks! |
thomaseizinger
left a comment
There was a problem hiding this comment.
Thanks! I've left some more comments but the direction here looks good! :)
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
thomaseizinger
left a comment
There was a problem hiding this comment.
Great! :)
Almost there. I'd like to see whether we can remove the length-prefixing.
|
I knew should be a better solution to wrap behavior :) |
thomaseizinger
left a comment
There was a problem hiding this comment.
Awesome! Some final requests and then we can merge this!
json and cbor messages
thomaseizinger
left a comment
There was a problem hiding this comment.
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.
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:cborjsonBoth define a
Behaviourtype-alias that comes with aCodecimplementation which uses the respectiveserdecrate to serialize and deserialize the messages.Fixes #3905.
Notes & open questions
Behaviorstruct to use with theSerdeCodec<Request, Response>Behaviorwith thejsonorcborcodecChange checklist