forked from celestiaorg/rsmt2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codecs.go
39 lines (34 loc) · 1.4 KB
/
codecs.go
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
package rsmt2d
import "fmt"
const (
// Leopard is a codec that was originally implemented in the C++ library
// https://github.com/catid/leopard. rsmt2d uses a Go port of the C++
// library in https://github.com/klauspost/reedsolomon. The Leopard codec
// uses 8-bit leopard for shards less than or equal to 256. The Leopard
// codec uses 16-bit leopard for shards greater than 256.
Leopard = "Leopard"
)
type Codec interface {
// Encode encodes original data, automatically extracting share size.
// There must be no missing shares. Only returns parity shares.
Encode(data [][]byte) ([][]byte, error)
// Decode decodes sparse original + parity data, automatically extracting share size.
// Missing shares must be nil. Returns original + parity data.
Decode(data [][]byte) ([][]byte, error)
// MaxChunks returns the max number of chunks this codec supports in a 2D
// original data square.
MaxChunks() int
// Name returns the name of the codec.
Name() string
// ValidateChunkSize returns an error if this codec does not support
// chunkSize. Returns nil if chunkSize is supported.
ValidateChunkSize(chunkSize int) error
}
// codecs is a global map used for keeping track of registered codecs for testing and JSON unmarshalling
var codecs = make(map[string]Codec)
func registerCodec(ct string, codec Codec) {
if codecs[ct] != nil {
panic(fmt.Sprintf("%v already registered", codec))
}
codecs[ct] = codec
}