question: how-to construct a message based on ABNF syntax
nskalis opened this issue · comments
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
- Compressed-Flag = 0 (1 byte)
- Message-Length = 0 (4 byte unsigned integer)
- Message = NULL byte, I think
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.
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>>])
Glad you figured it out. Binary patterns are super powerful in elixir/erlang.