Introduce and use nested length reader/writers
In !542 (merged) it bothered me that there were separate function for calculating the encoded length of an address, from the functions which actually did the encoding and decoding. Indeed this led to a bug where the code would accept binary IPv4 and IPv6 addresses with junk after the actual address - a bug which was not so easy to see (or even explain).
Here I provide an affordance which makes those kind of bugs much harder to write. For reading it's quite straightforward. Writing is a little more complicated, and has a wrinkle in the error handling because Writeable
is infallible.
CC @dgoulet. The reader part of this is what I was suggesting in !542 (comment 2809462) et seq.
I haven't done any kind of survey to see where else this might be of use. My functions assume that the length field always immediately precedes the actual bytes that the length field counts. I hope this is a true assumption...