Loading...
Searching...
No Matches

Simple XOR based coding algorithms. More...

Detailed Description

Simple XOR based coding algorithms.

Warning
This feature is experimental!
This is a very basic implementation, it can only recover 1 lost block in 3 and only has a 33% chance of recovering two consecutive lost blocks. API / Algorithm might change if that means we can do better.

Files

file  xor.h
 XOR coding definitions.
 

Macros

#define CONFIG_CODING_XOR_CHECK_BYTES   3U
 Number of payload bytes per parity byte.
 
#define CODING_XOR_PARITY_LEN(in)
 Get the size of the needed parity buffer for a given payload size.
 

Functions

void coding_xor_generate (void *data, size_t len, uint8_t *parity)
 Generate parity and mix data buffer.
 
bool coding_xor_recover (void *data, size_t len, uint8_t *parity, uint8_t *blocks, size_t block_size, bool recover_parity)
 Restore and unmix buffer.
 

Macro Definition Documentation

◆ CODING_XOR_PARITY_LEN

#define CODING_XOR_PARITY_LEN (   in)
Value:
#define CONFIG_CODING_XOR_CHECK_BYTES
Number of payload bytes per parity byte.
Definition xor.h:41

Get the size of the needed parity buffer for a given payload size.

Parameters
inPayload length

Definition at line 49 of file xor.h.

◆ CONFIG_CODING_XOR_CHECK_BYTES

#define CONFIG_CODING_XOR_CHECK_BYTES   3U

Number of payload bytes per parity byte.

Definition at line 41 of file xor.h.

Function Documentation

◆ coding_xor_generate()

void coding_xor_generate ( void *  data,
size_t  len,
uint8_t *  parity 
)

Generate parity and mix data buffer.

This generates parity data to recover one in CONFIG_CODING_XOR_CHECK_BYTES bytes. The data buffer is then mixed to distribute bytes amongst transfer blocks, so that the chance for consecutive bytes to be in the same block is lowered.

Parameters
[in,out]dataThe data buffer to be processed
[in]lenSize of the data buffer
[out]parityBuffer to hold parity data. Must be at least CODING_XOR_PARITY_LEN(len) bytes

◆ coding_xor_recover()

bool coding_xor_recover ( void *  data,
size_t  len,
uint8_t *  parity,
uint8_t *  blocks,
size_t  block_size,
bool  recover_parity 
)

Restore and unmix buffer.

Parameters
[in,out]dataThe data buffer to be restored
[in]lenSize of the data buffer
[in,out]parityBuffer with parity data. Must be at least CODING_XOR_PARITY_LEN(len) bytes
[in,out]blocksBitfieled to indicate which blocks were received. This indicates the presence of both data and parity blocks. Parity blocks are appended after the last data block. If a block was restored it's bit will be set.
[in]block_sizeSize of a data/payload block
[in]recover_parityIf true, missing parity blocks will be re-generated from data blocks.
Returns
True if all data blocks were recovered