-
Notifications
You must be signed in to change notification settings - Fork 652
/
codec.go
38 lines (30 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
36
37
38
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package vertex
import (
"time"
"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"
"github.com/ava-labs/avalanchego/utils/units"
)
const (
CodecVersion uint16 = 0
CodecVersionWithStopVtx uint16 = 1
// maxSize is the maximum allowed vertex size. It is necessary to deter DoS
maxSize = units.MiB
)
var Codec codec.Manager
func init() {
lc0 := linearcodec.New(time.Time{}, []string{reflectcodec.DefaultTagName + "V0"}, maxSize)
lc1 := linearcodec.New(time.Time{}, []string{reflectcodec.DefaultTagName + "V1"}, maxSize)
Codec = codec.NewManager(maxSize)
err := utils.Err(
Codec.RegisterCodec(CodecVersion, lc0),
Codec.RegisterCodec(CodecVersionWithStopVtx, lc1),
)
if err != nil {
panic(err)
}
}