Created
March 9, 2016 20:32
-
-
Save OleMchls/856b232ed2b4db67265b to your computer and use it in GitHub Desktop.
HPACK RFC Binary sigil
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule RFCBinaries do | |
def sigil_b(string, []) do | |
string | |
|> String.split("\n") | |
|> Enum.map(fn(part) -> String.split(part, "|") |> List.first end) | |
|> Enum.map(fn(part) -> String.split(part, " ") end) | |
|> List.flatten | |
|> Enum.filter(&(byte_size(&1) > 0)) | |
|> Enum.map(fn(part) -> String.to_integer(part, 16) end) | |
|> Enum.map(fn(i) -> << i::size(16) >> end) | |
|> Enum.reduce(fn(b, acc) -> acc <> b end) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test "Literal Header Field with Indexing", %{table: table} do | |
hbf = ~b/ | |
400a 6375 7374 6f6d 2d6b 6579 0d63 7573 | @.custom-key.cus | |
746f 6d2d 6865 6164 6572 | tom-header | |
/ | |
[ decoded_header | _ ] = HPack.decode(hbf, table) | |
assert decoded_header == { "custom-key", "custom-header" } | |
assert HPack.Table.size(table) == 55 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment