smee / binary

Clojure API for binary format I/O using java's stream apis
74 stars 10 forks source link

Q: header example #14

Closed smee closed 6 years ago

smee commented 6 years ago

Hi,

I'm extending your Bitcoin protocol example (demo/bitcoin.clj) to handle Bitcoin messages that are sent over the wire. The format is:

The problem I have run into is the checksum field between the length and the payload. I tried using something like:

(def payload (binary/blob :prefix length-and-checksum))

and having length-and-checksum reify BinaryIO so that it ignores the checksum when reading and just returns the length. However, for writing, I don't have access to the payload from here so I can't compute the checksum. Also, I'd prefer to compute the checksum outside of the codec.

Do you know of any way of doing this? Sorry if I missed something obvious and thank you for creating smee/binary.

Regards, @harrigan

smee commented 6 years ago

Hi @harrigan,

the main idea imho would be to use the header code: We have a payload with a prefix, so we need a way to parse the prefix (payload length and checksum) and use this information to parse the body (payload). Please refer to the example in the last commit.

Does this work for you?

harrigan commented 6 years ago

Thank you @smee! That is exactly what I was trying to do.

smee commented 6 years ago

Great. Since there is also a relevant bugfix to the padding codec make sure to use the new release 0.5.2