5.3. Library
5.3.1. Module spicy
5.3.1.1. Types
spicy::AddressFamily
Specifies an address’ IP family.
type AddressFamily = enum {
IPv4, # IP4 address
IPv6 # IPv6 address
};
spicy::Base64Stream
Captures the state of base64 encoding/decoding for the corresponding library functions.
spicy::BitOrder
Specifies the bit order for individual bit ranges inside a bitfield.
type BitOrder = enum {
LSB0, # bits are interpreted as lowest-significant-bit coming first
MSB0 # bits are interpreted as most-significant-bit coming first
};
spicy::ByteOrder
Specifies byte order for data operations.
type ByteOrder = enum {
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
};
spicy::Charset
Specifies the character set for bytes encoding/decoding.
type Charset = enum {
ASCII, # ASCII encoding
UTF8, # UTF8 encoding
UTF16LE, # UTF16 little endian encoding
UTF16BE, # UTF16 big endian encoding
};
spicy::DecodeErrorStrategy
Specifies how data is handled that’s not representable in a specified character set.
type DecodeErrorStrategy = enum {
IGNORE, # data is skipped but processing continues
REPLACE, # data is replaced with a valid place-holder and processing continues
STRICT # runtime error is triggered
};
spicy::MatchState
Captures state for incremental regular expression matching.
spicy::StreamStatistics
Captures stream statistics.
spicy::Protocol
Specifies a transport-layer protocol.
type Protocol = enum {
TCP,
UDP,
ICMP
};
spicy::RealType
Specifies the type of a real value.
type RealType = enum {
IEEE754_Single, # single precision in IEEE754 format
IEEE754_Double # double precision in IEEE754 format
};
spicy::ReassemblerPolicy
Specifies the policy for a sink’s reassembler when encountering overlapping data.
type ReassemblerPolicy = enum {
First # take the original data & discard the new data
};
spicy::Side
Specifies a side an operation should operate on.
type Side = enum {
Left, # operate on left side
Right, # operate on right side
Both # operate on both sides
};
spicy::Direction
Specifies direction of a search.
type Direction = enum {
Forward, # search forward
Backward, # search backward
};
spicy::ZlibStream
Captures the state of gzip decompression for the corresponding library functions.
5.3.1.2. 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::bytes_to_mac(value: bytes) : string
Returns a bytes value rendered as a MAC address string (i.e., colon-separated hex bytes).
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
Parses time from a 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.
function spicy::parse_address(s: string) : addr
Parses an address from a string. The address can be in standard IPv4 or IPv6
ASCII represententation. The function raises InvalidArgument
if the string
could not be parsed.
function spicy::parse_address(b: bytes) : addr
Parses an address from a bytes instance. The address can be in standard IPv4
or IPv6 ASCII represententation. The function raises InvalidArgument
if the
string could not be parsed.
function spicy::accept_input()
Reports a confirmation to the host application indicating that the parser appears to be processing the expected input format. It’s up to the host application how to use this information.
function spicy::decline_input(reason: string)
Reports a violation to the host application indicating that the parser appears not to be processing the expected input format. It’s up to the host application how to use this information.
Note that this does not automatically abort processing. If that’s desired, you need to trigger a parse error as well, e.g., by throwing an error, throw “<error message>”.
reason: user-presentable description of why the input seems wrong
5.3.2. Module filter
5.3.2.1. Types
filter::Zlib
A filter that performs zlib decompression.
type Zlib = unit;
filter::Base64Decode
A filter that performs Base64 decoding.
type Base64Decode = unit;