Spicy
Classes | Public Member Functions | Public Attributes | List of all members
spicy::rt::Sink Class Reference

#include <sink.h>

Public Member Functions

 Sink (const Sink &)=delete
 
 Sink (Sink &&)=default
 
Sinkoperator= (const Sink &)=delete
 
Sinkoperator= (Sink &&)=default
 
template<typename T >
void connect (spicy::rt::UnitRef< T > unit)
 
template<typename T >
void connect_filter (spicy::rt::UnitRef< T > unit)
 
void close ()
 
void connect_mime_type (const MIMEType &mt, const std::string &scope)
 
void connect_mime_type (const std::string &mt, const std::string &scope)
 
void connect_mime_type (const hilti::rt::Bytes &mt, const std::string &scope)
 
void gap (uint64_t seq, uint64_t len)
 
uint64_t sequence_number () const
 
void set_auto_trim (bool enable)
 
void set_initial_sequence_number (uint64_t seq)
 
void set_policy (sink::ReassemblerPolicy policy)
 
hilti::rt::integer::safe< uint64_t > size () const
 
void skip (uint64_t seq)
 
void trim (uint64_t seq)
 
void write (hilti::rt::Bytes data, std::optional< uint64_t > seq={}, std::optional< uint64_t > len={})
 

Public Attributes

filter::State< sink::detail::sink_name > _filter
 

Detailed Description

Runtime implementation for Spicy's sink type.

Note: When adding/changing methods that generated code acceeses, adapt the Spicy-side spicy_rt::Sink as well.

Member Function Documentation

◆ close()

void spicy::rt::Sink::close ( )
inline

Disconnects all units connected to the sink. They will then no longer receive any data written into the sink.

◆ connect()

template<typename T >
void spicy::rt::Sink::connect ( spicy::rt::UnitRef< T >  unit)
inline

Connects a unit instance to the sink. The unit will then receive any data written into the sink.

Parameters
unitunit to connect to the sink.

◆ connect_filter()

template<typename T >
void spicy::rt::Sink::connect_filter ( spicy::rt::UnitRef< T >  unit)
inline

Connects a filter unit to the sink. Any input will then pass through the filter before being forwarded tp parsing. Must not be called when data has been processed already. Multiple filters can be connected and will be chained.

Parameters
filterfilter unit to connect to the sink.
Exceptions
<tt>SinkError</tt>if the type cannot be parsed

◆ connect_mime_type() [1/3]

void Sink::connect_mime_type ( const MIMEType mt,
const std::string &  scope 
)

Connects new instances of all units to the sink that support a given MIME type. The lookup will consider all public units as well as units with the same scope. The units will then all receive any data written into the sink.

Parameters
mtMIME type to connect units for
scopeidentifier for the desired scope

◆ connect_mime_type() [2/3]

void spicy::rt::Sink::connect_mime_type ( const std::string &  mt,
const std::string &  scope 
)
inline

Connects new instances of all units to the sink that support a given MIME type. The lookup will consider all public units as well as units with the same scope. The units will then all receive any data written into the sink.

Parameters
mtMIME type to connect units for
scopeidentifier for the desired scope
Exceptions
<tt>mime::InvalidType</tt>if the type cannot be parsed

◆ connect_mime_type() [3/3]

void spicy::rt::Sink::connect_mime_type ( const hilti::rt::Bytes mt,
const std::string &  scope 
)
inline

Connects new instances of all units to the sink that support a given MIME type. The lookup will consider all public units as well as units with the same scope. The units will then all receive any data written into the sink.

Parameters
mtMIME type to connect units for
scopeidentifier for the desired scope
Exceptions
<tt>mime::InvalidType</tt>if the type cannot be parsed

◆ gap()

void Sink::gap ( uint64_t  seq,
uint64_t  len 
)

Reports a gap in the input stream.

Parameters
seqabsolute sequence number of the gap
lenlength of the gap

◆ sequence_number()

uint64_t spicy::rt::Sink::sequence_number ( ) const
inline

Returns the current position in the sequence space.

◆ set_auto_trim()

void spicy::rt::Sink::set_auto_trim ( bool  enable)
inline

Enable/disable automatic trimming.

Parameters
enabletrue to enable trimming, false to disable

◆ set_initial_sequence_number()

void spicy::rt::Sink::set_initial_sequence_number ( uint64_t  seq)
inline

Sets the initial sequence number.

Parameters
seqabsolute sequence number to associate with 1st byte of input.

◆ set_policy()

void spicy::rt::Sink::set_policy ( sink::ReassemblerPolicy  policy)
inline

Sets the sink's reassembler policy.

◆ size()

hilti::rt::integer::safe<uint64_t> spicy::rt::Sink::size ( ) const
inline

Returns the number of bytes written into the sink so far.

◆ skip()

void Sink::skip ( uint64_t  seq)

Skips ahead in the input stream.

Parameters
seqabsolute sequence number to skip ahead to

◆ trim()

void Sink::trim ( uint64_t  seq)

Trims buffered input.

Parameters
seqabsolute sequence number to trim up to.

◆ write()

void Sink::write ( hilti::rt::Bytes  data,
std::optional< uint64_t >  seq = {},
std::optional< uint64_t >  len = {} 
)

Writes data to the sink, forwarding it to all connected units.

Parameters
datadata to write
seqabsolute sequence number; defaults to end of current input
lenlength in sequence space; defaults to length of data

Member Data Documentation

◆ _filter

filter::State<sink::detail::sink_name> spicy::rt::Sink::_filter

Tracks connected filters. This is internal, but needs to be public because some free-standing functions are accessing it.

Todo:
(robin): We could probably declared the corresponding instantiations as friends.

The documentation for this class was generated from the following files: