combine v0.9.6 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

Functions

This parser parses N bits from the input

This parser parses N bytes from the input

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

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

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

Types

parser()
parser() :: Combine.parser
previous_parser()
previous_parser() :: Combine.previous_parser

Functions

bits(parser \\ nil, n)
bits(previous_parser, pos_integer) :: parser

This parser parses N bits from the input.

Example

iex> import Elixir.Combine.Parsers.Binary
...> Combine.parse("Hi", bits(8))
["H"]
...> Combine.parse("Hi", bits(8) |> bits(8))
["H", "i"]
bytes(parser \\ nil, n)
bytes(previous_parser, pos_integer) :: parser

This parser parses N bytes from the input.

Example

iex> import Elixir.Combine.Parsers.Binary
...> Combine.parse("Hi", bytes(1))
["H"]
...> Combine.parse("Hi", bytes(1) |> bytes(1))
["H", "i"]
float(parser \\ nil, size)
float(previous_parser, 32 | 64) :: parser

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]
int(parser \\ nil, size, endianness)
int(previous_parser, 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]
uint(parser \\ nil, size, endianness)
uint(previous_parser, 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]