forked from randombit/fecpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfecpp.h
66 lines (54 loc) · 1.43 KB
/
fecpp.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
/*
* Forward error correction based on Vandermonde matrices
*
* (C) 1997-1998 Luigi Rizzo ([email protected])
* (C) 2009 Jack Lloyd ([email protected])
*
* Distributed under the terms given in license.txt
*/
#ifndef FECPP_H__
#define FECPP_H__
#include <map>
#include <vector>
#include <tr1/functional>
namespace fecpp {
using std::size_t;
typedef unsigned char byte;
/**
* Forward error correction code
*/
class fec_code
{
public:
/**
* fec_code constructor
* @param K the number of shares needed for recovery
* @param N the number of shares generated
*/
fec_code(size_t K, size_t n);
size_t get_K() const { return K; }
size_t get_N() const { return N; }
/**
* @param input the data to FEC
* @param size the length in bytes of input
* @param out the output callback
*/
void encode(
const byte input[], size_t size,
std::tr1::function<void (size_t, size_t, const byte[], size_t)> out)
const;
/**
* @param shares map of share id to share contents
* @param share_size size in bytes of each share
* @param out the output callback
*/
void decode(
const std::map<size_t, const byte*>& shares, size_t share_size,
std::tr1::function<void (size_t, size_t, const byte[], size_t)> out)
const;
private:
size_t K, N;
std::vector<byte> enc_matrix;
};
}
#endif