Kitt.Util (kitt v0.4.0) View Source

Utility functions for interacting with data frames and elements for cleaner readability across modules.

Link to this section Summary

Functions

Converts a fixed-size byte identifier field to a human-readable integer

Converts an integer to its 4-byte binary representation for compatibility with common J2735 ID field spec.

Parses a keyword list of options and returns the desired output format for an encode function or the expected input format for a decode function.

Ensures data is converted to binary format for compatibility with various fixed-size data element fields in the J2735 message set.

Recursively converts a Kitt message struct to its equivalent Elixir map to allow it to be encoded to binary format. Reduces over the fields of the struct and converts it and any sub-fields defined as structs to a map.

Link to this section Functions

Specs

decode_id(binary()) :: non_neg_integer()

Converts a fixed-size byte identifier field to a human-readable integer

Specs

encode_id(non_neg_integer()) :: binary()

Converts an integer to its 4-byte binary representation for compatibility with common J2735 ID field spec.

Specs

get_format(keyword()) :: :hex | :binary | {:error, term()}

Parses a keyword list of options and returns the desired output format for an encode function or the expected input format for a decode function.

Defaults to hexadecimal format via the :hex atom if the :format option is not supplied.

Returns an {:error, reason} if an unsupported value is supplied for the :format option.

Specs

to_binary(binary() | integer()) :: binary()

Ensures data is converted to binary format for compatibility with various fixed-size data element fields in the J2735 message set.

Link to this function

to_map_recursive(element)

View Source

Specs

to_map_recursive(term()) :: term()

Recursively converts a Kitt message struct to its equivalent Elixir map to allow it to be encoded to binary format. Reduces over the fields of the struct and converts it and any sub-fields defined as structs to a map.

Specs

type(atom() | non_neg_integer()) :: {module(), atom()}