Combine.Parsers.Binary

This module defines common raw binary parsers, i.e. bits, bytes, uint, etc. To use them, just add import Combine.Parsers.Binary to your module, or reference them directly.

All of these parsers operate on, and return bitstrings as their results.

Summary

bits(n)

This parser parses N bits from the input

bits(parser, n)

Same as bits/1, but acts as a combinator

bytes(n)

This parser parses N bytes from the input

bytes(parser, n)

Same as bytes/1, but acts as a combinator

float(size)

This parser parses a n-bit floating point number from the input

float(parser, size)

Same as float/1, but acts as a combinator

int(size, endianness)

This parser parses a signed, n-bit integer from the input with the given endianness

int(parser, size, endianness)

Same as int/2, but acts as a combinator

uint(size, endianness)

This parser parses an unsigned, n-bit integer from the input with the given endianness

uint(parser, size, endianness)

Same as uint/2, but acts as a combinator

Types

Functions

bits(n)

Specs:

This parser parses N bits from the input.

Example

iex> import Elixir.Combine.Parsers.Binary
...> Combine.parse("Hi", bits(8))
["H"]
bits(parser, n)

Same as bits/1, but acts as a combinator.

bytes(n)

Specs:

  • bytes(pos_integer) :: parser

This parser parses N bytes from the input.

Example

iex> import Elixir.Combine.Parsers.Binary
...> Combine.parse("Hi", bytes(1))
["H"]
bytes(parser, n)

Same as bytes/1, but acts as a combinator.

float(size)

Specs:

This parser parses a n-bit floating point number from the input.

Example

iex> import Elixir.Combine.Parsers.Binary
...> Combine.parse(<<2.50::float-size(32)>>, float(32))
[2.5]
float(parser, size)

Same as float/1, but acts as a combinator.

int(size, endianness)

Specs:

  • int(pos_integer, :be | :le) :: parser

This parser parses a signed, n-bit integer from the input with the given endianness.

Example

iex> import Elixir.Combine.Parsers.Binary
...> Combine.parse(<<-85::big-signed-size(16),"-90"::binary>>, int(16, :be))
[-85]
int(parser, size, endianness)

Same as int/2, but acts as a combinator.

uint(size, endianness)

Specs:

  • uint(pos_integer, :be | :le) :: parser

This parser parses an unsigned, n-bit integer from the input with the given endianness.

Example

iex> import Elixir.Combine.Parsers.Binary
...> Combine.parse(<<85::big-unsigned-size(16), "-90"::binary>>, uint(16, :be))
[85]
uint(parser, size, endianness)

Same as uint/2, but acts as a combinator.