Petal.Bytes (petal v0.2.0) View Source

Collection of functions for working with byte arrays.

Link to this section Summary

Functions

Return the size in bytes from bits.

Round up the bits so that they are divisible by 8.

Check for the existance of the set bit from offset in bitfield.

Generate a binary that is n bytes long.

Pad the encoded payload to n bytes.

Link to this section Functions

Link to this function

byte_size_of_field(size)

View Source

Specs

byte_size_of_field(size :: pos_integer()) :: pos_integer()

Return the size in bytes from bits.

Specs

ceil_bits(size :: pos_integer()) :: pos_integer()

Round up the bits so that they are divisible by 8.

Link to this function

exists?(offset, bitfield)

View Source

Specs

exists?(offset :: pos_integer(), bitfield :: binary()) :: true | false

Check for the existance of the set bit from offset in bitfield.

Examples

iex> Petal.Bytes.exists?(23, <<0,0,1,0>>)
true

Specs

generate_n_bytes(n :: pos_integer()) :: binary()

Generate a binary that is n bytes long.

Link to this function

pad_encoded_payload(n, encoded)

View Source

Specs

pad_encoded_payload(n :: pos_integer(), encoded :: binary()) :: binary()

Pad the encoded payload to n bytes.

Examples

iex> Petal.Bytes.pad_encoded_payload(1, <<1>>)
<<0, 1>>