forked from celestiaorg/rsmt2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codecs.go
40 lines (33 loc) · 943 Bytes
/
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
40
package rsmt2d
import "fmt"
const (
LeopardFF16 = "LeopardFF16"
LeopardFF8 = "LeopardFF8"
RSGF8 = "RSFG8"
)
type Codec interface {
Encode(data [][]byte) ([][]byte, error)
Decode(data [][]byte) ([][]byte, error)
// maxChunks returns the max. number of chunks each code supports in a 2D square.
maxChunks() int
}
// codecs is a global map used for keeping track of which codecs are included during testing
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
}
func NewLeoRSFF16Codec() Codec {
if codec, has := codecs[LeopardFF16]; has {
return codec
}
panic("cannot use codec LeopardFF16 without the 'leopard' build tag")
}
func NewLeoRSFF8Codec() Codec {
if codec, has := codecs[LeopardFF8]; has {
return codec
}
panic("cannot use codec LeopardFF8 without the 'leopard' build tag")
}