Closed mhchia closed 5 years ago
As a developer I would expect to_bytes()
to return a byte literal. So yes, I tend to agree with this change. We can add a to_hex()
for syntactic sugar – I'm not super worried about the binascii dep as it's built in.
Thanks for the feedback. Good point for the dep. And this change also affects the return types, which might cause the code dependent on this package to fail.
Currently, if we initialize a
Multiaddr
, theto_bytes()
will output a hexlified value in bytes format. We need an additionalbinascii.unhexlify
to get the raw bytes.IMO we can just keep the raw bytes in
Multiaddr
, e.g.b'\x04\x7f\x00\x00\x01\x11\x04\xd2'
in the above example. This removes the dependency on binascii, additional converting overhead(we handle raw bytes in [de]serializations). And also aligns with theMultiaddr.Bytes()
ingo-multiaddr
.What do you guys think? cc @raulk @zixuanzh @zaibon @robzajac @alexh