EC Interfaces
Include the EC encoding and decoding interfaces.
Interface Format
int KsalEcEncode(uint8_t **data, uint8_t **parity, struct HecParam *param);
int KsalEcDecode(uint8_t **data, uint8_t **parity, struct HecParam *param);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
data |
Pointer array |
Indicates the pointer array of the data blocks. |
Input/Output |
parity |
Pointer array |
Indicates the pointer array of the parity blocks. |
Input/Output |
param |
Pointer to codec parameters |
Indicates the pointer to codec parameters. |
Input |
ret |
Integer |
Outputs 0 (success) or other values (failure). |
Output |
Data Structures
Member |
Type |
Description |
|---|---|---|
dataNum |
Integer |
Indicates the number of data blocks. |
parityNum |
Integer |
Indicates the number of parity blocks. |
sectorSize |
Integer |
Indicates the sector size, which is the minimum codec granularity. Currently, 4096 and 4160 are supported. |
blockSize |
Integer |
Indicates the size of a data block or parity block. The value must be an integer multiple of sectorSize. |
targetColNum |
Integer |
Indicates the number of lost blocks, which is used by the decoding interface. |
targetColArray[6] |
Integer |
Indicates the list of lost blocks. The value range of each entry is [0, dataNum + parityNum). |
version |
Integer |
Indicates the algorithm version. The current version is 0. |
Dependency
ksal/ksal_erasure_code.h
Example
- Write the EC test code.
- Create a test.c file.
vi test.c
- Press i to enter the insert mode and add the following test code to the file:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ksal/ksal_erasure_code.h> int main(int argc, char **argv) { struct HecParam param = {4, 2, 4096, 8192, 2, {3, 4}}; uint8_t tmp[20][8192]; uint8_t *ptrs[20]; uint8_t *bptrs[20]; for (size_t i = 0; i < param.dataNum + param.parityNum; ++i) { for (size_t j = 0; j < param.blockSize; j++) { tmp[i][j] = (uint8_t)rand() & 0xff; } ptrs[i] = tmp[i]; bptrs[i] = tmp[i]; } KsalEcEncode(ptrs, ptrs + param.dataNum, ¶m); bptrs[3] = tmp[18]; bptrs[4] = tmp[19]; KsalEcDecode(bptrs, bptrs + param.dataNum, ¶m); if (memcmp(bptrs[3], ptrs[3], param.blockSize) == 0 && memcmp(bptrs[4], ptrs[4], param.blockSize) == 0) { printf("decode succ!!\r\n"); } else { printf("decode fail!!\r\n"); } return 0; } - Press Esc to exit the insert mode. Type :wq! and press Enter to save and exit the file.
- Create a test.c file.
- Compile the test.c file into an executable file test.
gcc test.c -lksal -o test
- Run the test executable file.
./test
The command output is as follows:decode succ!!