princemaple / abnf_parsec

ABNF in, parser out
https://hexdocs.pm/abnf_parsec/AbnfParsec.html
MIT License
48 stars 2 forks source link

question: how-to construct a message based on ABNF syntax #8

Closed nskalis closed 4 years ago

nskalis commented 4 years ago

Hi,

Would you be so kind to advise how to use this library in order to build a 5 bytes header? More specifically,

Objective

I would like to make a gRPC call using a HTTP2 client (like Elixir Mint)

How it works

gRPC uses HTTP2 as a transport mechanism, based on the official docs https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md, the protocol follows the ABNF syntax

Focus / Length-Prefixed-Message

Based on help from the gRPC maintainers, what is important is the Length-Prefixed-Message, which is in the data itself. Length-Prefixed-Message isn't sent on-the-wire anywhere. It is just the name of some bytes. These things go in the HTTP payload/content. You would use the NULL byte for the 0.

Question

Assuming a request with an empty body and no compression

How can the body of such HTTP2 request can be constructed?

Note

I would appreciate your help and advice as this is my very first Elixir exercise.

nskalis commented 4 years ago

I guess I was wrong, this is what I needed I think:

IO.iodata_to_binary([<<0::unsigned-integer-size(8)-big>>, <<len::unsigned-integer-size(32)-big>>, <<0>>])
princemaple commented 4 years ago

Glad you figured it out. Binary patterns are super powerful in elixir/erlang.