forked from ipld/go-ipld-prime
/
multicodecRegistry.go
35 lines (30 loc) · 1.14 KB
/
multicodecRegistry.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
package cidlink
import "fmt"
var (
multicodecDecodeTable MulticodecDecodeTable
multicodecEncodeTable MulticodecEncodeTable
)
func init() {
multicodecEncodeTable = make(MulticodecEncodeTable)
multicodecDecodeTable = make(MulticodecDecodeTable)
}
// RegisterMulticodecDecoder is used to register multicodec features.
// It adjusts a global registry and may only be used at program init time;
// it is meant to provide a plugin system, not a configuration mechanism.
func RegisterMulticodecDecoder(hook uint64, fn MulticodecDecoder) {
_, exists := multicodecDecodeTable[hook]
if exists {
panic(fmt.Errorf("multicodec decoder already registered for %x", hook))
}
multicodecDecodeTable[hook] = fn
}
// RegisterMulticodecEncoder is used to register multicodec features.
// It adjusts a global registry and may only be used at program init time;
// it is meant to provide a plugin system, not a configuration mechanism.
func RegisterMulticodecEncoder(hook uint64, fn MulticodecEncoder) {
_, exists := multicodecEncodeTable[hook]
if exists {
panic(fmt.Errorf("multicodec encoder already registered for %x", hook))
}
multicodecEncodeTable[hook] = fn
}