You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But what I would like to do is deserialize the ip block into a std::net::SocketAddr struct. I've tried various approaches including using the "new type" pattern over SocketAddr but I can't seem to figure out how to get it to work:
It seems that the problem is that serde's deserializer for SocketAddr expects a string of the form 1.2.3.4:5678, whereas BEP-0005 uses what it calls "compact IP address/port info", which is just 6 binary bytes. You'll need to write a custom serializer and deserializer that know how to work with this format and then tell serde to use it with the #[serde(with=...)] attribute (documented at https://serde.rs/field-attrs.html).
You may also be happier with the bendy-specific API; while it's a little bit more verbose than serde is when everything works, it is much easier to write custom encoding and decoding functions using the bendy API.
Hi there,
Thanks for the handy library!
I'm trying to deserialize an
ip
block from the Bittorrent DHT according to BEP 5.I can use the following to deserialize the
ip
block into a byte vector:This works and gives me:
KRPCMessage { transaction_id: "aa", type_code: "r", version: None, response: {"id": [50, 245, 78, 105, 115, 81, 255, 74, 236, 41, 205, 186, 171, 242, 251, 227, 70, 124, 194, 103]}, ip: [70, 66, 178, 80, 26, 225] }
But what I would like to do is deserialize the ip block into a
std::net::SocketAddr
struct. I've tried various approaches including using the "new type" pattern overSocketAddr
but I can't seem to figure out how to get it to work:I always get the error:
It seems that it always try to decode the block as a utf-8 string.
Can anyone guide me on how to accomplish this? Please let me know if there any obvious errors—I'm new to Rust.
The text was updated successfully, but these errors were encountered: