github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/state/metadata_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 state
     5  
     6  import (
     7  	"errors"
     8  	"math"
     9  
    10  	"github.com/MetalBlockchain/metalgo/codec"
    11  	"github.com/MetalBlockchain/metalgo/codec/linearcodec"
    12  )
    13  
    14  const (
    15  	CodecVersion0Tag        = "v0"
    16  	CodecVersion0    uint16 = 0
    17  
    18  	CodecVersion1Tag        = "v1"
    19  	CodecVersion1    uint16 = 1
    20  )
    21  
    22  var MetadataCodec codec.Manager
    23  
    24  func init() {
    25  	c0 := linearcodec.New([]string{CodecVersion0Tag})
    26  	c1 := linearcodec.New([]string{CodecVersion0Tag, CodecVersion1Tag})
    27  	MetadataCodec = codec.NewManager(math.MaxInt32)
    28  
    29  	err := errors.Join(
    30  		MetadataCodec.RegisterCodec(CodecVersion0, c0),
    31  		MetadataCodec.RegisterCodec(CodecVersion1, c1),
    32  	)
    33  	if err != nil {
    34  		panic(err)
    35  	}
    36  }