Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: header example #14

Closed
smee opened this issue Jan 24, 2018 · 3 comments
Closed

Q: header example #14

smee opened this issue Jan 24, 2018 · 3 comments

Comments

@smee
Copy link
Owner

smee commented Jan 24, 2018

Hi,

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

  • magic (4 bytes)
  • command (12 bytes)
  • length (4 bytes)
  • checksum (4 bytes)
  • payload (variable length)

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
Copy link
Owner Author

smee commented Jan 24, 2018

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
Copy link
Contributor

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

@smee
Copy link
Owner Author

smee commented Jan 25, 2018

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

@smee smee closed this as completed Jan 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants