BinFormat.FieldType.Util

Implementations of the AST generator functions for builtin types with the BinFormat.FieldType.BuiltIn struct replaced by the relevant variables.

These functions are useful for other types and are provided to reduce duplication.

Summary

Functions

Add an implementation of field to the packet structure

Builds a binary pattern for an Elixir built in binary type

Builds a struct definition for a simple field

Builds a struct pattern for a simple field

Functions

add_field(field)

Add an implementation of field to the packet structure

Adds an field to the end of the current packet structure. The field should be an implementation of the BinFormat.Field protocol.

standard_bin_pattern(name, type, size, options, module, prefix)

Builds a binary pattern for an Elixir built in binary type.

Returns the equivalent of << … full_name :: type-option1-option2-size(s), … >> where option1 and option2 are members of the list options and s is the value of size.

This can be used for both building and matching patterns.

standard_struct_def(name, default)

Builds a struct definition for a simple field.

Returns the equivalent of defstruct ... name: default, ... in a struct definition.

standard_struct_pattern(name, module, prefix)

Builds a struct pattern for a simple field.

Returns the equivalent of %Module{... name: full_name, ...} where full_name is name with prefix appended at the start.

This can be used for both building and matching patterns.