5.3. Library

5.3.1. Module spicy Types


Specifies an address’ IP family.

type AddressFamily = {
    IPv4, # IP4 address
    IPv6  # IPv6 address


Captures the state of base64 encoding/decoding for the corresponding library functions.


Specifies the bit order for individual bit ranges inside a bitfield.

type BitOrder = {
    LSB0,     # bits are interpreted as lowest-significant-bit coming first
    MSB0      # bits are interpreted as most-significant-bit coming first


Specifies byte order for data operations.

type ByteOrder = {
    Little,   # data is in little-endian byte order
    Big,      # data is in big-endian byte order
    Network,  # data is in network byte order (same a big endian)
    Host      # data is in byte order of the host we are executing on


Captures state for incremental regular expression matching.


Specifies a transport-layer protocol.

type Protocol = {


Specifies the type of a real value.

type RealType = {
    IEEE754_Single, # single precision in IEEE754 format
    IEEE754_Double  # double precision in IEEE754 format


Specifies the policy for a sink’s reassembler when encountering overlapping data.

type ReassemblerPolicy = {
    First # take the original data & discard the new data


Specifies a side an operation should operate on.

type Side = {
    Left,    # operate on left side
    Right,   # operate on right side
    Both     # operate on both sides


Specifies direction of a search.

type Direction = {
    Forward, # search forward
    Backward, # search backward


Captures the state of gzip decompression for the corresponding library functions. Functions

function spicy::zlib_init(window_bits: int64) : ZlibStream

Initializes a zlib stream for decompression.

window_bits: Same as the corresponding parameter for zlib’s inflateInit2 (see https://www.zlib.net/manual.html).

Will throw a ZlibError exception if initialization fails.

function spicy::zlib_decompress(inout stream_: ZlibStream, data: bytes) : bytes

Decompresses a chunk of data through the given zlib stream.

function spicy::zlib_finish(inout stream_: ZlibStream) : bytes

Finalizes a zlib stream used for decompression.

function spicy::base64_encode(inout stream_: Base64Stream, data: bytes) : bytes

Encodes a stream of data into base64.

function spicy::base64_decode(inout stream_: Base64Stream, data: bytes) : bytes

Decodes a stream of base64 data back into the clear.

function spicy::base64_finish(inout stream_: Base64Stream) : bytes

Finalizes a base64 stream used for decoding or encoding.

function spicy::crc32_init() : uint64

Returns the initialization value for CRC32 computation.

function spicy::crc32_add(crc: uint64, data: bytes) : uint64

Computes a running CRC32.

function spicy::current_time() : time

Returns the current wall clock time.

function spicy::mktime(y: uint64, m: uint64, d: uint64, H: uint64, M: uint64, S: uint64) : time

Constructs a time value from a tuple of broken-out elements specifying local time.

  • y: year (1970-…)
  • m: month (1-12)
  • d: day (1-31)
  • H: hour (0-23)
  • M: minute (0-59)
  • S: second (0-59)

function spicy::bytes_to_hexstring(value: bytes) : string

Returns a bytes value rendered as a hex string.

function spicy::getenv(name: string) : optional<string>

Returns the value of an environment variable, if set.

function spicy::strftime(format: string, timestamp: time) : string

Formats a time according to user-specified format string.

This function uses the currently active locale and timezone to format values. Formatted strings cannot exceed 128 bytes.

The format string can contain format specifiers supported by POSIX strftime, see https://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html.

This function can raise InvalidArgument if the timestamp could not be converted to local time or formatted.

function spicy::strptime(buf: string, format: string) : time

Parse time from string.

This function uses the currently active locale and timezone to parse values.

The format string can contain format specifiers supported by POSIX strptime, see https://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html.

This function raises InvalidArgument if the string could not be parsed with the given format string, or OutOfRange if the parsed time value cannot be represented.

5.3.2. Module filter Types


A filter that performs zlib decompression.

type Zlib = unit;


A filter that performs Base64 decoding.

type Base64Decode = unit;