-
Notifications
You must be signed in to change notification settings - Fork 671
/
codec.go
35 lines (28 loc) · 976 Bytes
/
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
// Copyright (C) 2019-2023, 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/codec/reflectcodec"
"github.com/ava-labs/avalanchego/utils/units"
)
const (
// maxSize is the maximum allowed vertex size. It is necessary to deter DoS
maxSize = units.MiB
codecVersion uint16 = 0
codecVersionWithStopVtx uint16 = 1
)
var c codec.Manager
func init() {
lc := linearcodec.New([]string{reflectcodec.DefaultTagName + "V0"}, maxSize)
lc2 := linearcodec.New([]string{reflectcodec.DefaultTagName + "V1"}, maxSize)
c = codec.NewManager(maxSize)
// for backward compatibility, still register the initial codec version
if err := c.RegisterCodec(codecVersion, lc); err != nil {
panic(err)
}
if err := c.RegisterCodec(codecVersionWithStopVtx, lc2); err != nil {
panic(err)
}
}