Skip to main content

Module binary

Module binary 

Source
Available on crate feature types only.
Expand description

§Type parser for binary encoded types

This module provides functions to parse a binary encoded type into a Type. The binary encoding is a compact representation of a type that can be used to serialize and deserialize types.

The binary encoding is a sequence of bytes that represents a type. The encoding is a simple grammar that can be parsed into a type. The grammar is defined as follows:

type     = (filled | option | code::VOID | code::NIL) eof
filled   = code::ANY | union | specific
specific = code::TYPE | code::BOOL | code::CHAR | code::INT
         | code::FLOAT | code::SYMBOL | code::BINARY
         | array | pair | lambda
array    = code::ARRAY filled-option fixed
pair     = code::PAIR filled-option filled-option
lambda   = code::LAMBDA params variadic return
params   = (filled-option)*
variadic = (code::VARIADIC filled-option)?
return   = code::RETURN (code::VOID | filled-option)
option   = code::OPTION filled
union    = code::UNION specific specific+ code::END
fixed    = (fixed0 | fixed1 | fixed2 | fixed3 | fixed4)?
fixed0   = code::FIXED0..=code::FIXED0_MAX
fixed1   = code::FIXED1..=code::FIXED1_MAX byte
fixed2   = code::FIXED2..=code::FIXED2_MAX byte byte
fixed3   = code::FIXED3..=code::FIXED3_MAX byte byte byte
fixed4   = code::FIXED4..=code::FIXED4_MAX byte byte byte byte
byte     = 0x00..=0xFF

Functions§

parse
Parse a type code stream into a type.
parse_array
Parse a type code stream into an array type.
parse_filled
Parse a type code stream into a filled type.
parse_filled_option
Parse a type code stream into a filled type or an option type.
parse_fixed
Parse a type code stream into an optional fixed length value.
parse_lambda
Parse a type code stream into a lambda type.
parse_option
Parse a type code stream into an option type.
parse_pair
Parse a type code stream into a pair type.
parse_params
Parse a type code stream into a sequence of parameters, which may filled or option types. The sequence may be of zero length. Parses until no more parameters can be found.
parse_return
Parse a type code stream into a return type.
parse_specific
Parse a type code stream into a specific type.
parse_union
Parse a type code stream into a union type.
parse_variadic
Parse a type code stream into an optional variadic type.