-
Notifications
You must be signed in to change notification settings - Fork 661
/
codec.go
41 lines (33 loc) · 1.05 KB
/
codec.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
41
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package vertex
import (
"github.com/ava-labs/avalanchego/codec"
"github.com/ava-labs/avalanchego/codec/linearcodec"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/utils/wrappers"
)
const (
// maxSize is the maximum allowed vertex size. It is necessary to deter DoS
maxSize = units.MiB
// noEpochTransitionsCodecVersion is the codec version that was used when
// there were no epoch transitions
noEpochTransitionsCodecVersion = uint16(0)
// apricotCodecVersion is the codec version that was used when we added
// epoch transitions
apricotCodecVersion = uint16(1)
)
var c codec.Manager
func init() {
codecV0 := linearcodec.New("serializeV0", maxSize)
codecV1 := linearcodec.New("serializeV1", maxSize)
c = codec.NewManager(maxSize)
errs := wrappers.Errs{}
errs.Add(
c.RegisterCodec(noEpochTransitionsCodecVersion, codecV0),
c.RegisterCodec(apricotCodecVersion, codecV1),
)
if errs.Errored() {
panic(errs.Err)
}
}