The data structures necessary for the encoding/decoding must first be created using calling Fn fec_new with the desired parameters. The code descriptor returned by the function must be passed to other functions, and destroyed calling Fn fec_free
Allowed values for k and n depend on a compile-time value of Fa GF_BITS and must be k <= n <= 2^GF_BITS. Best performance is achieved with GF_BITS=8, although the code supports also GF_BITS=16.
Encoding is done by calling Fn fec_encode and passing it pointers to the code descriptor, the source and destination data packets, the index of the packet to be produced, and the size of the packet.
Fn fec_decode with pointers to the code, received packets, indexes of received packets, and packet size. Decoding is done in place, possibly shuffling the arrays passed as parameters. Decoding is deterministic as long as the received packets are different. The decoding procedure does some limited testing on this and returns if parameters are invalid.
#include <fec.h>
/*
* example of sender code
*/
void *code ;
int n, k ;
void *src[] ;
void *pkt ;
code = new_code (k, n );
for (i = 0 ; i < k ; i++ )
src[i] = .. pointer to i-th source packet ..
for (each packet to transmit) {
i = ... index of the packet ;
fec_encode(code, src, pkt, i, size) ;
.. use packet in pkt
}
fec_free(code) ;
/*
* example of receiver code
*/
void *code ;
int n, k ;
void *data[] ;
int *ix[] ;
code = new_code (k, n );
for (i = 0 ; i < k ; i++ ) {
... receive a new packet ...
data[i] = .. pointer to i-th source packet ..
ix[i] = .. index of i-th source packet ..
}
fec_decode(code, data, ix, size) ;
/*
* now data[] has pointers to the source packets
*/