Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Ipv4Addr seems to be serializes as text string, not as a number. #52

Closed
vi opened this issue Dec 15, 2017 · 5 comments
Closed

Ipv4Addr seems to be serializes as text string, not as a number. #52

vi opened this issue Dec 15, 2017 · 5 comments

Comments

@vi
Copy link

vi commented Dec 15, 2017

Unlike in JSON, I expect std::net::Ipv4Addr to be 5 bytes in CBOR...

@sfackler
Copy link
Collaborator

This will be fixed by #51.

@pyfisch
Copy link
Owner

pyfisch commented Dec 25, 2017

See #54. But it is only 5 Bytes long with IPs like 8.8.8.8 where all numbers are small. (IPAddrs are serialized as an array)

@vi
Copy link
Author

vi commented Dec 25, 2017

Isn't IPv4 (IPv6) address better be a byte buffer, not 4 (16) numbers?

@pyfisch
Copy link
Owner

pyfisch commented Dec 25, 2017

Serde only offers two options to serialize the IP address "127.0.0.1":

  1. is_human_readable() == true: "127.0.0.1" as a canonical string
  2. is_human_readable() == false: [127, 0, 0, 1] as an array of four numbers.

For serde-cbor it would be better either as:

  1. a byte buffer (as you suggested): b"\x7f\x00\x00\x01"
  2. as a 32 bit unsigned integer: 2130706433i32

But these serializations are not supported by serde. (For other binary formats like bincode this does not matter because an IPv4Addr is serialized as four bytes either way.

@vi
Copy link
Author

vi commented Dec 25, 2017

Can one somehow make IPv{4,6}Addr markable with serde_bytes?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants