github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/avalanche/vertex/codec.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package vertex
     5  
     6  import (
     7  	"errors"
     8  
     9  	"github.com/MetalBlockchain/metalgo/codec"
    10  	"github.com/MetalBlockchain/metalgo/codec/linearcodec"
    11  	"github.com/MetalBlockchain/metalgo/codec/reflectcodec"
    12  	"github.com/MetalBlockchain/metalgo/utils/units"
    13  )
    14  
    15  const (
    16  	CodecVersion            uint16 = 0
    17  	CodecVersionWithStopVtx uint16 = 1
    18  
    19  	// maxSize is the maximum allowed vertex size. It is necessary to deter DoS
    20  	maxSize = units.MiB
    21  )
    22  
    23  var Codec codec.Manager
    24  
    25  func init() {
    26  	lc0 := linearcodec.New([]string{reflectcodec.DefaultTagName + "V0"})
    27  	lc1 := linearcodec.New([]string{reflectcodec.DefaultTagName + "V1"})
    28  
    29  	Codec = codec.NewManager(maxSize)
    30  	err := errors.Join(
    31  		Codec.RegisterCodec(CodecVersion, lc0),
    32  		Codec.RegisterCodec(CodecVersionWithStopVtx, lc1),
    33  	)
    34  	if err != nil {
    35  		panic(err)
    36  	}
    37  }