Warning: This is an old version. The latest stable version is Version 11.0.1.

# class encoder¶

Scope: kodo_slide

## Brief description¶

Implementation of a complete RLNC sliding window encoder.

## Member functions (public)¶

 encoder (uint32_t symbol_size = 1300, finite_field field = finite_field::binary8) void reset () void reconfigure (uint32_t symbol_size, finite_field field) finite_field field () const uint64_t symbol_size () const uint64_t stream_symbols () const uint64_t stream_lower_bound () const uint64_t stream_upper_bound () const uint64_t push_front_symbol (const uint8_t * symbol) uint64_t pop_back_symbol () uint64_t window_symbols () const uint64_t window_lower_bound () const uint64_t window_upper_bound () const void set_window (uint64_t lower_bound, uint64_t symbols) uint64_t coefficient_vector_size () const void set_seed (uint64_t seed_value) void generate (uint8_t * coefficients) void write_source_symbol (uint8_t * symbol, uint64_t index) void write_symbol (uint8_t * symbol, const uint8_t * coefficients) void set_log_stdout () void set_zone_prefix (const std::string & zone_prefix)

## Member Function Description¶

encoder (uint32_t symbol_size = 1300, finite_field field = finite_field::binary8)

The encoder constructor.

Parameter symbol_size:
the size of a symbol in bytes
Parameter field:
the chosen finite field

void reset ()
Resets the coder and ensures that the object is in a clean state. A coder may be reset many times.

void reconfigure (uint32_t symbol_size, finite_field field)

Reconfigures the encoder with the given parameters. This is useful for reusing an existing coder. Note that the reconfiguration always implies a reset, so the coder will be in a clean state after this operation

Parameter symbol_size:
the size of a symbol in bytes
Parameter field:
the chosen finite field

finite_field field ()
Returns:
The finite field used.

uint64_t symbol_size ()
Returns:
The size of a symbol in the stream in bytes.

uint64_t stream_symbols ()
Returns:

The total number of symbols available in memory at the encoder. The number of symbols in the coding window MUST be less than or equal to this number. The total range of valid symbol indices is:

for (uint64_t i = 0; i < stream_symbols(); ++i)
{
std::cout << i + stream_lower_bound() << "\n";
}


uint64_t stream_lower_bound ()
Returns:
The index of the oldest symbol known by the encoder. This symbol may not be inside the window but can be included in the window if needed.

uint64_t stream_upper_bound ()
Returns:
The upper bound of the stream. The range of valid symbol indices goes from [ encoder::stream_lower_bound() , encoder::stream_upper_bound() ). Note the stream is a half-open interval. Going from encoder::stream_lower_bound() to encoder::stream_upper_bound() - 1.

uint64_t push_front_symbol (const uint8_t * symbol)

Adds a new symbol to the front of the encoder. Increments the number of symbols in the stream and increases the encoder::stream_upper_bound() . This does not move the encoder’s window. So if you want to include this new symbol in the encoding you should update the window also:

encoder.set_window(encoder.stream_lower_bound(),
encoder.stream_symbols());

Parameter symbol:
Pointer to the symbol. Note, the caller must ensure that the memory of the symbol remains valid as long as the symbol is included in the stream. The caller is responsible for freeing the memory if needed. Once the symbol is popped from the stream.
Returns:
The stream index of the symbol being added.

uint64_t pop_back_symbol ()

Remove the “oldest” symbol from the stream. Increments the encoder::stream_lower_bound() . This does not update the encoder’s window. So you need to make sure the symbol is not longer included in any encodings e.g.:

encoder.set_window(encoder.stream_lower_bound(),
encoder.stream_symbols());

Returns:
The index of the symbol being removed

uint64_t window_symbols ()
Returns:
The number of symbols currently in the coding window. The window must be within the bounds of the stream.

uint64_t window_lower_bound ()
Returns:
The index of the “oldest” symbol in the coding window.

uint64_t window_upper_bound ()
Returns:
The upper bound of the window. The range of valid symbol indices goes from [ encoder::window_lower_bound() , encoder::window_upper_bound() ). Note the window is a half-open interval. Going from encoder::window_lower_bound() to encoder::window_upper_bound() - 1.

void set_window (uint64_t lower_bound, uint64_t symbols)

The window represents the symbols which will be included in the next encoding. The window cannot exceed the bounds of the stream. Example: If window_lower_bound=4 and window_symbol=3 the following symbol indices will be included 4,5,6

Parameter lower_bound:
Sets the index of the oldest symbol in the window.
Parameter symbols:
Sets number of symbols within the window.

uint64_t coefficient_vector_size ()
Returns:
The size of the coefficient vector in the current window in bytes. The number of coefficients is equal to the number of symbols in the window. The size in bits of each coefficients depends on the finite field chosen. A custom coding scheme can be implemented by generating the coding vector manually. Alternatively the built-in generator can be used. See encoder::set_seed (…) and encoder::generate (…).

void set_seed (uint64_t seed_value)

Seed the internal random generator function. If using the same seed on the encoder and decoder the exact same set of coefficients will be generated.

Parameter seed_value:
A value for the seed.

void generate (uint8_t * coefficients)

Generate coding coefficients for the symbols in the coding window according to the specified seed (see encoder::set_seed (…)).

Parameter coefficients:
Buffer where the coding coefficients should be stored. This buffer must be encoder::coefficient_vector_size() large in bytes.

void write_source_symbol (uint8_t * symbol, uint64_t index)

Write a source symbol to the symbol buffer.

Parameter symbol:
The buffer where the source symbol will be stored. The symbol buffer must be encoder::symbol_size() large.
Parameter index:
The symbol index which should be written.

void write_symbol (uint8_t * symbol, const uint8_t * coefficients)

Write an encoded symbol according to the coding coefficients.

Parameter symbol:
The buffer where the encoded symbol will be stored. The symbol buffer must be encoder::symbol_size() large.
Parameter coefficients:
The coding coefficients. These must have the memory layout required (see README.rst). A compatible format can be created using encoder::generate (…)

void set_log_stdout ()
Enables logging in a stack. The output will be written to standard out.

void set_zone_prefix (const std::string & zone_prefix)

Sets a zone prefix for the logging output. The zone prefix will be appended to all the output. This makes it possible to have two stacks that both log to standard out, but still differentiate the output.

Parameter zone_prefix:
The zone prefix to append to all logging zones