-
Notifications
You must be signed in to change notification settings - Fork 28
/
rs.h
88 lines (75 loc) · 2.01 KB
/
rs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef __RS_H_
#define __RS_H_
/* use small value to save memory */
#ifndef DATA_SHARDS_MAX
#define DATA_SHARDS_MAX (255)
#endif
/* use other memory allocator */
#ifndef RS_MALLOC
#define RS_MALLOC(x) malloc(x)
#endif
#ifndef RS_FREE
#define RS_FREE(x) free(x)
#endif
#ifndef RS_CALLOC
#define RS_CALLOC(n, x) calloc(n, x)
#endif
typedef struct _reed_solomon {
int data_shards;
int parity_shards;
int shards;
unsigned char* m;
unsigned char* parity;
} reed_solomon;
/**
* MUST initial one time
* */
void fec_init(void);
reed_solomon* reed_solomon_new(int data_shards, int parity_shards);
void reed_solomon_release(reed_solomon* rs);
/**
* encode one shard
* input:
* rs
* data_blocks[rs->data_shards][block_size]
* fec_blocks[rs->data_shards][block_size]
* */
int reed_solomon_encode(reed_solomon* rs,
unsigned char** data_blocks,
unsigned char** fec_blocks,
int block_size);
/**
* decode one shard
* input:
* rs
* original data_blocks[rs->data_shards][block_size]
* dec_fec_blocks[nr_fec_blocks][block_size]
* fec_block_nos: fec pos number in original fec_blocks
* erased_blocks: erased blocks in original data_blocks
* nr_fec_blocks: the number of erased blocks
* */
int reed_solomon_decode(reed_solomon* rs,
unsigned char **data_blocks,
int block_size,
unsigned char **dec_fec_blocks,
unsigned int *fec_block_nos,
unsigned int *erased_blocks,
int nr_fec_blocks);
/**
* encode a big size of buffer
* input:
* rs
* nr_shards: assert(0 == nr_shards % rs->data_shards)
* shards[nr_shards][block_size]
* */
int reed_solomon_encode2(reed_solomon* rs, unsigned char** shards, int nr_shards, int block_size);
/**
* reconstruct a big size of buffer
* input:
* rs
* nr_shards: assert(0 == nr_shards % rs->data_shards)
* shards[nr_shards][block_size]
* marks[nr_shards] marks as errors
* */
int reed_solomon_reconstruct(reed_solomon* rs, unsigned char** shards, unsigned char* marks, int nr_shards, int block_size);
#endif