Files
bft/msm/encoding.canoto.go
zeekayandHanzo Dev 974d0d5422 rename: drop the upstream protocol name from the tree
The module is luxfi/bft and that is now the only name it answers to.

- simplex/ -> engine/. Upstream's module is named for the protocol, so its root
  package and its engine package shared that name; under luxfi/bft the engine
  package would have collided with the module's own root package. It is the
  consensus engine, so engine.Epoch and engine.NewEpoch read without stutter.
- Identifiers keep the qualifier where it carries meaning and only change the
  word: a block produced by this protocol as against a pre-existing chain's block
  is a real distinction, so makeNonSimplexBlock became makeNonBFTBlock,
  lastNonSimplexInnerBlockHeight became lastNonBFTInnerBlockHeight,
  newSnowToSimplexChain became newSnowToBFTChain. Dropping the qualifier outright
  would have left names that assert nothing.
- The canoto-tagged fields of StateMachineMetadata lose the prefix entirely:
  EpochInfo, ProtocolMetadata, Blacklist. The wire format is unchanged — canoto
  keys off the tag numbers, which still read 1,2,3,4,5, and the generated
  .canoto.go files were renamed in step with the source. The msm fuzz and
  encoding round-trip tests cover this.
- Prose cites the protocol paper by reference number instead of by name, so the
  origin stays findable without the name. The HyperSDK sentence still says
  Avalanche because that sentence is about Avalanche's VM and is true.

Also here, from review of the logger port:
- monitor_test's Fatal panics instead of returning. It reported a state the
  caller had declared impossible and then carried on regardless, which made it
  the one Fatal in the tree that was weaker than the original.
- TestInstanceNonValidatorBootstraps asserts the property it is named for — that
  the node was still a non-validator when the bootstrap finished — rather than
  counting how many times a debug line was emitted. The count tracks how often
  onEpochChange happened to observe the branch, so transitions can coalesce; it
  measured 2 here where it had been reliably 3, and a logger-cost explanation was
  tested and refuted. The count never checked the property either way: a node
  that wrongly became a validator mid-bootstrap would still have counted 3.
- SilenceExceptKeywords documents last-call-wins, and Trace/Verbo now reaching
  hooks is recorded where a future hook author will see it.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-06 05:16:49 -07:00

1973 lines
59 KiB
Go

// Code generated by canoto. DO NOT EDIT.
// versions:
// canoto v0.19.0
// source: msm/encoding.go
package metadata
import (
"io"
"reflect"
"sync/atomic"
"github.com/StephenButtolph/canoto"
)
// Ensure that the generated code is compatible with the library version.
const (
_ uint = canoto.VersionCompatibility - 1
_ uint = 1 - canoto.VersionCompatibility
)
// Ensure that unused imports do not error
var _ = io.ErrUnexpectedEOF
const (
canotoNumber_StateMachineMetadata__EpochInfo = 1
canotoNumber_StateMachineMetadata__ProtocolMetadata = 2
canotoNumber_StateMachineMetadata__Blacklist = 3
canotoNumber_StateMachineMetadata__PChainHeight = 4
canotoNumber_StateMachineMetadata__Timestamp = 5
canotoNumber_StateMachineMetadata__ICMEpochInfo = 6
canotoNumber_StateMachineMetadata__AuxiliaryInfo = 7
canotoTag_StateMachineMetadata__EpochInfo = "\x0a" // canoto.Tag(canotoNumber_StateMachineMetadata__EpochInfo, canoto.Len)
canotoTag_StateMachineMetadata__ProtocolMetadata = "\x12" // canoto.Tag(canotoNumber_StateMachineMetadata__ProtocolMetadata, canoto.Len)
canotoTag_StateMachineMetadata__Blacklist = "\x1a" // canoto.Tag(canotoNumber_StateMachineMetadata__Blacklist, canoto.Len)
canotoTag_StateMachineMetadata__PChainHeight = "\x20" // canoto.Tag(canotoNumber_StateMachineMetadata__PChainHeight, canoto.Varint)
canotoTag_StateMachineMetadata__Timestamp = "\x28" // canoto.Tag(canotoNumber_StateMachineMetadata__Timestamp, canoto.Varint)
canotoTag_StateMachineMetadata__ICMEpochInfo = "\x32" // canoto.Tag(canotoNumber_StateMachineMetadata__ICMEpochInfo, canoto.Len)
canotoTag_StateMachineMetadata__AuxiliaryInfo = "\x3a" // canoto.Tag(canotoNumber_StateMachineMetadata__AuxiliaryInfo, canoto.Len)
)
type canotoData_StateMachineMetadata struct {
size uint64
}
// CanotoSpec returns the specification of this canoto message.
func (*StateMachineMetadata) CanotoSpec(types ...reflect.Type) *canoto.Spec {
types = append(types, reflect.TypeFor[StateMachineMetadata]())
var zero StateMachineMetadata
s := &canoto.Spec{
Name: "StateMachineMetadata",
Fields: []canoto.FieldType{
canoto.FieldTypeFromField(
/*type inference:*/ (&zero.EpochInfo),
/*FieldNumber: */ canotoNumber_StateMachineMetadata__EpochInfo,
/*Name: */ "EpochInfo",
/*FixedLength: */ 0,
/*Repeated: */ false,
/*OneOf: */ "",
/*Pointer: */ false,
/*types: */ types,
),
canoto.FieldTypeFromField(
/*type inference:*/ (&zero.ProtocolMetadata),
/*FieldNumber: */ canotoNumber_StateMachineMetadata__ProtocolMetadata,
/*Name: */ "ProtocolMetadata",
/*FixedLength: */ 0,
/*Repeated: */ false,
/*OneOf: */ "",
/*Pointer: */ false,
/*types: */ types,
),
canoto.FieldTypeFromField(
/*type inference:*/ (&zero.Blacklist),
/*FieldNumber: */ canotoNumber_StateMachineMetadata__Blacklist,
/*Name: */ "Blacklist",
/*FixedLength: */ 0,
/*Repeated: */ false,
/*OneOf: */ "",
/*Pointer: */ false,
/*types: */ types,
),
{
FieldNumber: canotoNumber_StateMachineMetadata__PChainHeight,
Name: "PChainHeight",
OneOf: "",
TypeUint: canoto.SizeOf(zero.PChainHeight),
},
{
FieldNumber: canotoNumber_StateMachineMetadata__Timestamp,
Name: "Timestamp",
OneOf: "",
TypeUint: canoto.SizeOf(zero.Timestamp),
},
canoto.FieldTypeFromField(
/*type inference:*/ (&zero.ICMEpochInfo),
/*FieldNumber: */ canotoNumber_StateMachineMetadata__ICMEpochInfo,
/*Name: */ "ICMEpochInfo",
/*FixedLength: */ 0,
/*Repeated: */ false,
/*OneOf: */ "",
/*Pointer: */ false,
/*types: */ types,
),
canoto.FieldTypeFromField(
/*type inference:*/ (zero.AuxiliaryInfo),
/*FieldNumber: */ canotoNumber_StateMachineMetadata__AuxiliaryInfo,
/*Name: */ "AuxiliaryInfo",
/*FixedLength: */ 0,
/*Repeated: */ false,
/*OneOf: */ "",
/*Pointer: */ true,
/*types: */ types,
),
},
}
s.CalculateCanotoCache()
return s
}
// UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
//
// During parsing, the canoto cache is saved.
func (c *StateMachineMetadata) UnmarshalCanoto(bytes []byte) error {
r := canoto.Reader{
B: bytes,
}
return c.UnmarshalCanotoFrom(r)
}
// UnmarshalCanotoFrom populates the struct from a [canoto.Reader]. Most users
// should just use UnmarshalCanoto.
//
// During parsing, the canoto cache is saved.
//
// This function enables configuration of reader options.
func (c *StateMachineMetadata) UnmarshalCanotoFrom(r canoto.Reader) error {
// Zero the struct before unmarshaling.
*c = StateMachineMetadata{}
atomic.StoreUint64(&c.canotoData.size, uint64(len(r.B)))
var minField uint32
for canoto.HasNext(&r) {
field, wireType, err := canoto.ReadTag(&r)
if err != nil {
return err
}
if field < minField {
return canoto.ErrInvalidFieldOrder
}
switch field {
case canotoNumber_StateMachineMetadata__EpochInfo:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
// Read the bytes for the field.
originalUnsafe := r.Unsafe
r.Unsafe = true
var msgBytes []byte
if err := canoto.ReadBytes(&r, &msgBytes); err != nil {
return err
}
if len(msgBytes) == 0 {
return canoto.ErrZeroValue
}
r.Unsafe = originalUnsafe
// Unmarshal the field from the bytes.
remainingBytes := r.B
r.B = msgBytes
if err := (&c.EpochInfo).UnmarshalCanotoFrom(r); err != nil {
return err
}
r.B = remainingBytes
case canotoNumber_StateMachineMetadata__ProtocolMetadata:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
// Read the bytes for the field.
originalUnsafe := r.Unsafe
r.Unsafe = true
var msgBytes []byte
if err := canoto.ReadBytes(&r, &msgBytes); err != nil {
return err
}
if len(msgBytes) == 0 {
return canoto.ErrZeroValue
}
r.Unsafe = originalUnsafe
// Unmarshal the field from the bytes.
remainingBytes := r.B
r.B = msgBytes
if err := (&c.ProtocolMetadata).UnmarshalCanotoFrom(r); err != nil {
return err
}
r.B = remainingBytes
case canotoNumber_StateMachineMetadata__Blacklist:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
// Read the bytes for the field.
originalUnsafe := r.Unsafe
r.Unsafe = true
var msgBytes []byte
if err := canoto.ReadBytes(&r, &msgBytes); err != nil {
return err
}
if len(msgBytes) == 0 {
return canoto.ErrZeroValue
}
r.Unsafe = originalUnsafe
// Unmarshal the field from the bytes.
remainingBytes := r.B
r.B = msgBytes
if err := (&c.Blacklist).UnmarshalCanotoFrom(r); err != nil {
return err
}
r.B = remainingBytes
case canotoNumber_StateMachineMetadata__PChainHeight:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.PChainHeight); err != nil {
return err
}
if canoto.IsZero(c.PChainHeight) {
return canoto.ErrZeroValue
}
case canotoNumber_StateMachineMetadata__Timestamp:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.Timestamp); err != nil {
return err
}
if canoto.IsZero(c.Timestamp) {
return canoto.ErrZeroValue
}
case canotoNumber_StateMachineMetadata__ICMEpochInfo:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
// Read the bytes for the field.
originalUnsafe := r.Unsafe
r.Unsafe = true
var msgBytes []byte
if err := canoto.ReadBytes(&r, &msgBytes); err != nil {
return err
}
if len(msgBytes) == 0 {
return canoto.ErrZeroValue
}
r.Unsafe = originalUnsafe
// Unmarshal the field from the bytes.
remainingBytes := r.B
r.B = msgBytes
if err := (&c.ICMEpochInfo).UnmarshalCanotoFrom(r); err != nil {
return err
}
r.B = remainingBytes
case canotoNumber_StateMachineMetadata__AuxiliaryInfo:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
// Read the bytes for the field.
originalUnsafe := r.Unsafe
r.Unsafe = true
var msgBytes []byte
if err := canoto.ReadBytes(&r, &msgBytes); err != nil {
return err
}
r.Unsafe = originalUnsafe
// Unmarshal the field from the bytes.
remainingBytes := r.B
r.B = msgBytes
c.AuxiliaryInfo = canoto.MakePointer(c.AuxiliaryInfo)
if err := (c.AuxiliaryInfo).UnmarshalCanotoFrom(r); err != nil {
return err
}
r.B = remainingBytes
default:
return canoto.ErrUnknownField
}
minField = field + 1
}
return nil
}
// ValidCanoto validates that the struct can be correctly marshaled into the
// Canoto format.
//
// Specifically, ValidCanoto ensures:
// 1. All OneOfs are specified at most once.
// 2. All strings are valid utf-8.
// 3. All custom fields are ValidCanoto.
func (c *StateMachineMetadata) ValidCanoto() bool {
if !(&c.EpochInfo).ValidCanoto() {
return false
}
if !(&c.ProtocolMetadata).ValidCanoto() {
return false
}
if !(&c.Blacklist).ValidCanoto() {
return false
}
if !(&c.ICMEpochInfo).ValidCanoto() {
return false
}
if c.AuxiliaryInfo != nil && !(c.AuxiliaryInfo).ValidCanoto() {
return false
}
return true
}
// CalculateCanotoCache populates size and OneOf caches based on the current
// values in the struct.
//
// It is not safe to copy this struct concurrently.
func (c *StateMachineMetadata) CalculateCanotoCache() {
var size uint64
(&c.EpochInfo).CalculateCanotoCache()
if fieldSize := (&c.EpochInfo).CachedCanotoSize(); fieldSize != 0 {
size += uint64(len(canotoTag_StateMachineMetadata__EpochInfo)) + canoto.SizeUint(fieldSize) + fieldSize
}
(&c.ProtocolMetadata).CalculateCanotoCache()
if fieldSize := (&c.ProtocolMetadata).CachedCanotoSize(); fieldSize != 0 {
size += uint64(len(canotoTag_StateMachineMetadata__ProtocolMetadata)) + canoto.SizeUint(fieldSize) + fieldSize
}
(&c.Blacklist).CalculateCanotoCache()
if fieldSize := (&c.Blacklist).CachedCanotoSize(); fieldSize != 0 {
size += uint64(len(canotoTag_StateMachineMetadata__Blacklist)) + canoto.SizeUint(fieldSize) + fieldSize
}
if !canoto.IsZero(c.PChainHeight) {
size += uint64(len(canotoTag_StateMachineMetadata__PChainHeight)) + canoto.SizeUint(c.PChainHeight)
}
if !canoto.IsZero(c.Timestamp) {
size += uint64(len(canotoTag_StateMachineMetadata__Timestamp)) + canoto.SizeUint(c.Timestamp)
}
(&c.ICMEpochInfo).CalculateCanotoCache()
if fieldSize := (&c.ICMEpochInfo).CachedCanotoSize(); fieldSize != 0 {
size += uint64(len(canotoTag_StateMachineMetadata__ICMEpochInfo)) + canoto.SizeUint(fieldSize) + fieldSize
}
if c.AuxiliaryInfo != nil {
(c.AuxiliaryInfo).CalculateCanotoCache()
fieldSize := (c.AuxiliaryInfo).CachedCanotoSize()
size += uint64(len(canotoTag_StateMachineMetadata__AuxiliaryInfo)) + canoto.SizeUint(fieldSize) + fieldSize
}
atomic.StoreUint64(&c.canotoData.size, size)
}
// CachedCanotoSize returns the previously calculated size of the Canoto
// representation from CalculateCanotoCache.
//
// If CalculateCanotoCache has not yet been called, it will return 0.
//
// If the struct has been modified since the last call to CalculateCanotoCache,
// the returned size may be incorrect.
func (c *StateMachineMetadata) CachedCanotoSize() uint64 {
return atomic.LoadUint64(&c.canotoData.size)
}
// MarshalCanoto returns the Canoto representation of this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *StateMachineMetadata) MarshalCanoto() []byte {
c.CalculateCanotoCache()
w := canoto.Writer{
B: make([]byte, 0, c.CachedCanotoSize()),
}
w = c.MarshalCanotoInto(w)
return w.B
}
// MarshalCanotoInto writes the struct into a [canoto.Writer] and returns the
// resulting [canoto.Writer]. Most users should just use MarshalCanoto.
//
// It is assumed that CalculateCanotoCache has been called since the last
// modification to this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *StateMachineMetadata) MarshalCanotoInto(w canoto.Writer) canoto.Writer {
if fieldSize := (&c.EpochInfo).CachedCanotoSize(); fieldSize != 0 {
canoto.Append(&w, canotoTag_StateMachineMetadata__EpochInfo)
canoto.AppendUint(&w, fieldSize)
w = (&c.EpochInfo).MarshalCanotoInto(w)
}
if fieldSize := (&c.ProtocolMetadata).CachedCanotoSize(); fieldSize != 0 {
canoto.Append(&w, canotoTag_StateMachineMetadata__ProtocolMetadata)
canoto.AppendUint(&w, fieldSize)
w = (&c.ProtocolMetadata).MarshalCanotoInto(w)
}
if fieldSize := (&c.Blacklist).CachedCanotoSize(); fieldSize != 0 {
canoto.Append(&w, canotoTag_StateMachineMetadata__Blacklist)
canoto.AppendUint(&w, fieldSize)
w = (&c.Blacklist).MarshalCanotoInto(w)
}
if !canoto.IsZero(c.PChainHeight) {
canoto.Append(&w, canotoTag_StateMachineMetadata__PChainHeight)
canoto.AppendUint(&w, c.PChainHeight)
}
if !canoto.IsZero(c.Timestamp) {
canoto.Append(&w, canotoTag_StateMachineMetadata__Timestamp)
canoto.AppendUint(&w, c.Timestamp)
}
if fieldSize := (&c.ICMEpochInfo).CachedCanotoSize(); fieldSize != 0 {
canoto.Append(&w, canotoTag_StateMachineMetadata__ICMEpochInfo)
canoto.AppendUint(&w, fieldSize)
w = (&c.ICMEpochInfo).MarshalCanotoInto(w)
}
if c.AuxiliaryInfo != nil {
fieldSize := (c.AuxiliaryInfo).CachedCanotoSize()
canoto.Append(&w, canotoTag_StateMachineMetadata__AuxiliaryInfo)
canoto.AppendUint(&w, fieldSize)
w = (c.AuxiliaryInfo).MarshalCanotoInto(w)
}
return w
}
const (
canotoNumber_ICMEpochInfo__EpochStartTime = 1
canotoNumber_ICMEpochInfo__EpochNumber = 2
canotoNumber_ICMEpochInfo__PChainEpochHeight = 3
canotoTag_ICMEpochInfo__EpochStartTime = "\x08" // canoto.Tag(canotoNumber_ICMEpochInfo__EpochStartTime, canoto.Varint)
canotoTag_ICMEpochInfo__EpochNumber = "\x10" // canoto.Tag(canotoNumber_ICMEpochInfo__EpochNumber, canoto.Varint)
canotoTag_ICMEpochInfo__PChainEpochHeight = "\x18" // canoto.Tag(canotoNumber_ICMEpochInfo__PChainEpochHeight, canoto.Varint)
)
type canotoData_ICMEpochInfo struct {
size uint64
}
// CanotoSpec returns the specification of this canoto message.
func (*ICMEpochInfo) CanotoSpec(...reflect.Type) *canoto.Spec {
var zero ICMEpochInfo
s := &canoto.Spec{
Name: "ICMEpochInfo",
Fields: []canoto.FieldType{
{
FieldNumber: canotoNumber_ICMEpochInfo__EpochStartTime,
Name: "EpochStartTime",
OneOf: "",
TypeUint: canoto.SizeOf(zero.EpochStartTime),
},
{
FieldNumber: canotoNumber_ICMEpochInfo__EpochNumber,
Name: "EpochNumber",
OneOf: "",
TypeUint: canoto.SizeOf(zero.EpochNumber),
},
{
FieldNumber: canotoNumber_ICMEpochInfo__PChainEpochHeight,
Name: "PChainEpochHeight",
OneOf: "",
TypeUint: canoto.SizeOf(zero.PChainEpochHeight),
},
},
}
s.CalculateCanotoCache()
return s
}
// UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
//
// During parsing, the canoto cache is saved.
func (c *ICMEpochInfo) UnmarshalCanoto(bytes []byte) error {
r := canoto.Reader{
B: bytes,
}
return c.UnmarshalCanotoFrom(r)
}
// UnmarshalCanotoFrom populates the struct from a [canoto.Reader]. Most users
// should just use UnmarshalCanoto.
//
// During parsing, the canoto cache is saved.
//
// This function enables configuration of reader options.
func (c *ICMEpochInfo) UnmarshalCanotoFrom(r canoto.Reader) error {
// Zero the struct before unmarshaling.
*c = ICMEpochInfo{}
atomic.StoreUint64(&c.canotoData.size, uint64(len(r.B)))
var minField uint32
for canoto.HasNext(&r) {
field, wireType, err := canoto.ReadTag(&r)
if err != nil {
return err
}
if field < minField {
return canoto.ErrInvalidFieldOrder
}
switch field {
case canotoNumber_ICMEpochInfo__EpochStartTime:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.EpochStartTime); err != nil {
return err
}
if canoto.IsZero(c.EpochStartTime) {
return canoto.ErrZeroValue
}
case canotoNumber_ICMEpochInfo__EpochNumber:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.EpochNumber); err != nil {
return err
}
if canoto.IsZero(c.EpochNumber) {
return canoto.ErrZeroValue
}
case canotoNumber_ICMEpochInfo__PChainEpochHeight:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.PChainEpochHeight); err != nil {
return err
}
if canoto.IsZero(c.PChainEpochHeight) {
return canoto.ErrZeroValue
}
default:
return canoto.ErrUnknownField
}
minField = field + 1
}
return nil
}
// ValidCanoto validates that the struct can be correctly marshaled into the
// Canoto format.
//
// Specifically, ValidCanoto ensures:
// 1. All OneOfs are specified at most once.
// 2. All strings are valid utf-8.
// 3. All custom fields are ValidCanoto.
func (c *ICMEpochInfo) ValidCanoto() bool {
return true
}
// CalculateCanotoCache populates size and OneOf caches based on the current
// values in the struct.
//
// It is not safe to copy this struct concurrently.
func (c *ICMEpochInfo) CalculateCanotoCache() {
var size uint64
if !canoto.IsZero(c.EpochStartTime) {
size += uint64(len(canotoTag_ICMEpochInfo__EpochStartTime)) + canoto.SizeUint(c.EpochStartTime)
}
if !canoto.IsZero(c.EpochNumber) {
size += uint64(len(canotoTag_ICMEpochInfo__EpochNumber)) + canoto.SizeUint(c.EpochNumber)
}
if !canoto.IsZero(c.PChainEpochHeight) {
size += uint64(len(canotoTag_ICMEpochInfo__PChainEpochHeight)) + canoto.SizeUint(c.PChainEpochHeight)
}
atomic.StoreUint64(&c.canotoData.size, size)
}
// CachedCanotoSize returns the previously calculated size of the Canoto
// representation from CalculateCanotoCache.
//
// If CalculateCanotoCache has not yet been called, it will return 0.
//
// If the struct has been modified since the last call to CalculateCanotoCache,
// the returned size may be incorrect.
func (c *ICMEpochInfo) CachedCanotoSize() uint64 {
return atomic.LoadUint64(&c.canotoData.size)
}
// MarshalCanoto returns the Canoto representation of this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *ICMEpochInfo) MarshalCanoto() []byte {
c.CalculateCanotoCache()
w := canoto.Writer{
B: make([]byte, 0, c.CachedCanotoSize()),
}
w = c.MarshalCanotoInto(w)
return w.B
}
// MarshalCanotoInto writes the struct into a [canoto.Writer] and returns the
// resulting [canoto.Writer]. Most users should just use MarshalCanoto.
//
// It is assumed that CalculateCanotoCache has been called since the last
// modification to this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *ICMEpochInfo) MarshalCanotoInto(w canoto.Writer) canoto.Writer {
if !canoto.IsZero(c.EpochStartTime) {
canoto.Append(&w, canotoTag_ICMEpochInfo__EpochStartTime)
canoto.AppendUint(&w, c.EpochStartTime)
}
if !canoto.IsZero(c.EpochNumber) {
canoto.Append(&w, canotoTag_ICMEpochInfo__EpochNumber)
canoto.AppendUint(&w, c.EpochNumber)
}
if !canoto.IsZero(c.PChainEpochHeight) {
canoto.Append(&w, canotoTag_ICMEpochInfo__PChainEpochHeight)
canoto.AppendUint(&w, c.PChainEpochHeight)
}
return w
}
const (
canotoNumber_AuxiliaryInfo__Info = 1
canotoNumber_AuxiliaryInfo__PrevAuxInfoSeq = 2
canotoNumber_AuxiliaryInfo__VersionID = 3
canotoTag_AuxiliaryInfo__Info = "\x0a" // canoto.Tag(canotoNumber_AuxiliaryInfo__Info, canoto.Len)
canotoTag_AuxiliaryInfo__PrevAuxInfoSeq = "\x10" // canoto.Tag(canotoNumber_AuxiliaryInfo__PrevAuxInfoSeq, canoto.Varint)
canotoTag_AuxiliaryInfo__VersionID = "\x18" // canoto.Tag(canotoNumber_AuxiliaryInfo__VersionID, canoto.Varint)
)
type canotoData_AuxiliaryInfo struct {
size uint64
}
// CanotoSpec returns the specification of this canoto message.
func (*AuxiliaryInfo) CanotoSpec(...reflect.Type) *canoto.Spec {
var zero AuxiliaryInfo
s := &canoto.Spec{
Name: "AuxiliaryInfo",
Fields: []canoto.FieldType{
{
FieldNumber: canotoNumber_AuxiliaryInfo__Info,
Name: "Info",
OneOf: "",
TypeBytes: true,
},
{
FieldNumber: canotoNumber_AuxiliaryInfo__PrevAuxInfoSeq,
Name: "PrevAuxInfoSeq",
OneOf: "",
TypeUint: canoto.SizeOf(zero.PrevAuxInfoSeq),
},
{
FieldNumber: canotoNumber_AuxiliaryInfo__VersionID,
Name: "VersionID",
OneOf: "",
TypeUint: canoto.SizeOf(zero.VersionID),
},
},
}
s.CalculateCanotoCache()
return s
}
// UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
//
// During parsing, the canoto cache is saved.
func (c *AuxiliaryInfo) UnmarshalCanoto(bytes []byte) error {
r := canoto.Reader{
B: bytes,
}
return c.UnmarshalCanotoFrom(r)
}
// UnmarshalCanotoFrom populates the struct from a [canoto.Reader]. Most users
// should just use UnmarshalCanoto.
//
// During parsing, the canoto cache is saved.
//
// This function enables configuration of reader options.
func (c *AuxiliaryInfo) UnmarshalCanotoFrom(r canoto.Reader) error {
// Zero the struct before unmarshaling.
*c = AuxiliaryInfo{}
atomic.StoreUint64(&c.canotoData.size, uint64(len(r.B)))
var minField uint32
for canoto.HasNext(&r) {
field, wireType, err := canoto.ReadTag(&r)
if err != nil {
return err
}
if field < minField {
return canoto.ErrInvalidFieldOrder
}
switch field {
case canotoNumber_AuxiliaryInfo__Info:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadBytes(&r, &c.Info); err != nil {
return err
}
if len(c.Info) == 0 {
return canoto.ErrZeroValue
}
case canotoNumber_AuxiliaryInfo__PrevAuxInfoSeq:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.PrevAuxInfoSeq); err != nil {
return err
}
if canoto.IsZero(c.PrevAuxInfoSeq) {
return canoto.ErrZeroValue
}
case canotoNumber_AuxiliaryInfo__VersionID:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.VersionID); err != nil {
return err
}
if canoto.IsZero(c.VersionID) {
return canoto.ErrZeroValue
}
default:
return canoto.ErrUnknownField
}
minField = field + 1
}
return nil
}
// ValidCanoto validates that the struct can be correctly marshaled into the
// Canoto format.
//
// Specifically, ValidCanoto ensures:
// 1. All OneOfs are specified at most once.
// 2. All strings are valid utf-8.
// 3. All custom fields are ValidCanoto.
func (c *AuxiliaryInfo) ValidCanoto() bool {
return true
}
// CalculateCanotoCache populates size and OneOf caches based on the current
// values in the struct.
//
// It is not safe to copy this struct concurrently.
func (c *AuxiliaryInfo) CalculateCanotoCache() {
var size uint64
if len(c.Info) != 0 {
size += uint64(len(canotoTag_AuxiliaryInfo__Info)) + canoto.SizeBytes(c.Info)
}
if !canoto.IsZero(c.PrevAuxInfoSeq) {
size += uint64(len(canotoTag_AuxiliaryInfo__PrevAuxInfoSeq)) + canoto.SizeUint(c.PrevAuxInfoSeq)
}
if !canoto.IsZero(c.VersionID) {
size += uint64(len(canotoTag_AuxiliaryInfo__VersionID)) + canoto.SizeUint(c.VersionID)
}
atomic.StoreUint64(&c.canotoData.size, size)
}
// CachedCanotoSize returns the previously calculated size of the Canoto
// representation from CalculateCanotoCache.
//
// If CalculateCanotoCache has not yet been called, it will return 0.
//
// If the struct has been modified since the last call to CalculateCanotoCache,
// the returned size may be incorrect.
func (c *AuxiliaryInfo) CachedCanotoSize() uint64 {
return atomic.LoadUint64(&c.canotoData.size)
}
// MarshalCanoto returns the Canoto representation of this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *AuxiliaryInfo) MarshalCanoto() []byte {
c.CalculateCanotoCache()
w := canoto.Writer{
B: make([]byte, 0, c.CachedCanotoSize()),
}
w = c.MarshalCanotoInto(w)
return w.B
}
// MarshalCanotoInto writes the struct into a [canoto.Writer] and returns the
// resulting [canoto.Writer]. Most users should just use MarshalCanoto.
//
// It is assumed that CalculateCanotoCache has been called since the last
// modification to this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *AuxiliaryInfo) MarshalCanotoInto(w canoto.Writer) canoto.Writer {
if len(c.Info) != 0 {
canoto.Append(&w, canotoTag_AuxiliaryInfo__Info)
canoto.AppendBytes(&w, c.Info)
}
if !canoto.IsZero(c.PrevAuxInfoSeq) {
canoto.Append(&w, canotoTag_AuxiliaryInfo__PrevAuxInfoSeq)
canoto.AppendUint(&w, c.PrevAuxInfoSeq)
}
if !canoto.IsZero(c.VersionID) {
canoto.Append(&w, canotoTag_AuxiliaryInfo__VersionID)
canoto.AppendUint(&w, c.VersionID)
}
return w
}
const (
canotoNumber_EpochInfo__PChainReferenceHeight = 1
canotoNumber_EpochInfo__EpochNumber = 2
canotoNumber_EpochInfo__PrevSealingBlockHash = 3
canotoNumber_EpochInfo__NextPChainReferenceHeight = 4
canotoNumber_EpochInfo__PrevVMBlockSeq = 5
canotoNumber_EpochInfo__BlockValidationDescriptor = 6
canotoNumber_EpochInfo__NextEpochApprovals = 7
canotoNumber_EpochInfo__SealingBlockSeq = 8
canotoTag_EpochInfo__PChainReferenceHeight = "\x08" // canoto.Tag(canotoNumber_EpochInfo__PChainReferenceHeight, canoto.Varint)
canotoTag_EpochInfo__EpochNumber = "\x10" // canoto.Tag(canotoNumber_EpochInfo__EpochNumber, canoto.Varint)
canotoTag_EpochInfo__PrevSealingBlockHash = "\x1a" // canoto.Tag(canotoNumber_EpochInfo__PrevSealingBlockHash, canoto.Len)
canotoTag_EpochInfo__NextPChainReferenceHeight = "\x20" // canoto.Tag(canotoNumber_EpochInfo__NextPChainReferenceHeight, canoto.Varint)
canotoTag_EpochInfo__PrevVMBlockSeq = "\x28" // canoto.Tag(canotoNumber_EpochInfo__PrevVMBlockSeq, canoto.Varint)
canotoTag_EpochInfo__BlockValidationDescriptor = "\x32" // canoto.Tag(canotoNumber_EpochInfo__BlockValidationDescriptor, canoto.Len)
canotoTag_EpochInfo__NextEpochApprovals = "\x3a" // canoto.Tag(canotoNumber_EpochInfo__NextEpochApprovals, canoto.Len)
canotoTag_EpochInfo__SealingBlockSeq = "\x40" // canoto.Tag(canotoNumber_EpochInfo__SealingBlockSeq, canoto.Varint)
)
type canotoData_EpochInfo struct {
size uint64
}
// CanotoSpec returns the specification of this canoto message.
func (*EpochInfo) CanotoSpec(types ...reflect.Type) *canoto.Spec {
types = append(types, reflect.TypeFor[EpochInfo]())
var zero EpochInfo
s := &canoto.Spec{
Name: "EpochInfo",
Fields: []canoto.FieldType{
{
FieldNumber: canotoNumber_EpochInfo__PChainReferenceHeight,
Name: "PChainReferenceHeight",
OneOf: "",
TypeUint: canoto.SizeOf(zero.PChainReferenceHeight),
},
{
FieldNumber: canotoNumber_EpochInfo__EpochNumber,
Name: "EpochNumber",
OneOf: "",
TypeUint: canoto.SizeOf(zero.EpochNumber),
},
{
FieldNumber: canotoNumber_EpochInfo__PrevSealingBlockHash,
Name: "PrevSealingBlockHash",
OneOf: "",
TypeFixedBytes: uint64(len(zero.PrevSealingBlockHash)),
},
{
FieldNumber: canotoNumber_EpochInfo__NextPChainReferenceHeight,
Name: "NextPChainReferenceHeight",
OneOf: "",
TypeUint: canoto.SizeOf(zero.NextPChainReferenceHeight),
},
{
FieldNumber: canotoNumber_EpochInfo__PrevVMBlockSeq,
Name: "PrevVMBlockSeq",
OneOf: "",
TypeUint: canoto.SizeOf(zero.PrevVMBlockSeq),
},
canoto.FieldTypeFromField(
/*type inference:*/ (zero.BlockValidationDescriptor),
/*FieldNumber: */ canotoNumber_EpochInfo__BlockValidationDescriptor,
/*Name: */ "BlockValidationDescriptor",
/*FixedLength: */ 0,
/*Repeated: */ false,
/*OneOf: */ "",
/*Pointer: */ true,
/*types: */ types,
),
canoto.FieldTypeFromField(
/*type inference:*/ (zero.NextEpochApprovals),
/*FieldNumber: */ canotoNumber_EpochInfo__NextEpochApprovals,
/*Name: */ "NextEpochApprovals",
/*FixedLength: */ 0,
/*Repeated: */ false,
/*OneOf: */ "",
/*Pointer: */ true,
/*types: */ types,
),
{
FieldNumber: canotoNumber_EpochInfo__SealingBlockSeq,
Name: "SealingBlockSeq",
OneOf: "",
TypeUint: canoto.SizeOf(zero.SealingBlockSeq),
},
},
}
s.CalculateCanotoCache()
return s
}
// UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
//
// During parsing, the canoto cache is saved.
func (c *EpochInfo) UnmarshalCanoto(bytes []byte) error {
r := canoto.Reader{
B: bytes,
}
return c.UnmarshalCanotoFrom(r)
}
// UnmarshalCanotoFrom populates the struct from a [canoto.Reader]. Most users
// should just use UnmarshalCanoto.
//
// During parsing, the canoto cache is saved.
//
// This function enables configuration of reader options.
func (c *EpochInfo) UnmarshalCanotoFrom(r canoto.Reader) error {
// Zero the struct before unmarshaling.
*c = EpochInfo{}
atomic.StoreUint64(&c.canotoData.size, uint64(len(r.B)))
var minField uint32
for canoto.HasNext(&r) {
field, wireType, err := canoto.ReadTag(&r)
if err != nil {
return err
}
if field < minField {
return canoto.ErrInvalidFieldOrder
}
switch field {
case canotoNumber_EpochInfo__PChainReferenceHeight:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.PChainReferenceHeight); err != nil {
return err
}
if canoto.IsZero(c.PChainReferenceHeight) {
return canoto.ErrZeroValue
}
case canotoNumber_EpochInfo__EpochNumber:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.EpochNumber); err != nil {
return err
}
if canoto.IsZero(c.EpochNumber) {
return canoto.ErrZeroValue
}
case canotoNumber_EpochInfo__PrevSealingBlockHash:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
const (
expectedLength = len(c.PrevSealingBlockHash)
expectedLengthUint64 = uint64(expectedLength)
)
var length uint64
if err := canoto.ReadUint(&r, &length); err != nil {
return err
}
if length != expectedLengthUint64 {
return canoto.ErrInvalidLength
}
if expectedLength > len(r.B) {
return io.ErrUnexpectedEOF
}
copy((&c.PrevSealingBlockHash)[:], r.B)
if canoto.IsZero(c.PrevSealingBlockHash) {
return canoto.ErrZeroValue
}
r.B = r.B[expectedLength:]
case canotoNumber_EpochInfo__NextPChainReferenceHeight:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.NextPChainReferenceHeight); err != nil {
return err
}
if canoto.IsZero(c.NextPChainReferenceHeight) {
return canoto.ErrZeroValue
}
case canotoNumber_EpochInfo__PrevVMBlockSeq:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.PrevVMBlockSeq); err != nil {
return err
}
if canoto.IsZero(c.PrevVMBlockSeq) {
return canoto.ErrZeroValue
}
case canotoNumber_EpochInfo__BlockValidationDescriptor:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
// Read the bytes for the field.
originalUnsafe := r.Unsafe
r.Unsafe = true
var msgBytes []byte
if err := canoto.ReadBytes(&r, &msgBytes); err != nil {
return err
}
r.Unsafe = originalUnsafe
// Unmarshal the field from the bytes.
remainingBytes := r.B
r.B = msgBytes
c.BlockValidationDescriptor = canoto.MakePointer(c.BlockValidationDescriptor)
if err := (c.BlockValidationDescriptor).UnmarshalCanotoFrom(r); err != nil {
return err
}
r.B = remainingBytes
case canotoNumber_EpochInfo__NextEpochApprovals:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
// Read the bytes for the field.
originalUnsafe := r.Unsafe
r.Unsafe = true
var msgBytes []byte
if err := canoto.ReadBytes(&r, &msgBytes); err != nil {
return err
}
r.Unsafe = originalUnsafe
// Unmarshal the field from the bytes.
remainingBytes := r.B
r.B = msgBytes
c.NextEpochApprovals = canoto.MakePointer(c.NextEpochApprovals)
if err := (c.NextEpochApprovals).UnmarshalCanotoFrom(r); err != nil {
return err
}
r.B = remainingBytes
case canotoNumber_EpochInfo__SealingBlockSeq:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.SealingBlockSeq); err != nil {
return err
}
if canoto.IsZero(c.SealingBlockSeq) {
return canoto.ErrZeroValue
}
default:
return canoto.ErrUnknownField
}
minField = field + 1
}
return nil
}
// ValidCanoto validates that the struct can be correctly marshaled into the
// Canoto format.
//
// Specifically, ValidCanoto ensures:
// 1. All OneOfs are specified at most once.
// 2. All strings are valid utf-8.
// 3. All custom fields are ValidCanoto.
func (c *EpochInfo) ValidCanoto() bool {
if c.BlockValidationDescriptor != nil && !(c.BlockValidationDescriptor).ValidCanoto() {
return false
}
if c.NextEpochApprovals != nil && !(c.NextEpochApprovals).ValidCanoto() {
return false
}
return true
}
// CalculateCanotoCache populates size and OneOf caches based on the current
// values in the struct.
//
// It is not safe to copy this struct concurrently.
func (c *EpochInfo) CalculateCanotoCache() {
var size uint64
if !canoto.IsZero(c.PChainReferenceHeight) {
size += uint64(len(canotoTag_EpochInfo__PChainReferenceHeight)) + canoto.SizeUint(c.PChainReferenceHeight)
}
if !canoto.IsZero(c.EpochNumber) {
size += uint64(len(canotoTag_EpochInfo__EpochNumber)) + canoto.SizeUint(c.EpochNumber)
}
if !canoto.IsZero(c.PrevSealingBlockHash) {
size += uint64(len(canotoTag_EpochInfo__PrevSealingBlockHash)) + canoto.SizeBytes((&c.PrevSealingBlockHash)[:])
}
if !canoto.IsZero(c.NextPChainReferenceHeight) {
size += uint64(len(canotoTag_EpochInfo__NextPChainReferenceHeight)) + canoto.SizeUint(c.NextPChainReferenceHeight)
}
if !canoto.IsZero(c.PrevVMBlockSeq) {
size += uint64(len(canotoTag_EpochInfo__PrevVMBlockSeq)) + canoto.SizeUint(c.PrevVMBlockSeq)
}
if c.BlockValidationDescriptor != nil {
(c.BlockValidationDescriptor).CalculateCanotoCache()
fieldSize := (c.BlockValidationDescriptor).CachedCanotoSize()
size += uint64(len(canotoTag_EpochInfo__BlockValidationDescriptor)) + canoto.SizeUint(fieldSize) + fieldSize
}
if c.NextEpochApprovals != nil {
(c.NextEpochApprovals).CalculateCanotoCache()
fieldSize := (c.NextEpochApprovals).CachedCanotoSize()
size += uint64(len(canotoTag_EpochInfo__NextEpochApprovals)) + canoto.SizeUint(fieldSize) + fieldSize
}
if !canoto.IsZero(c.SealingBlockSeq) {
size += uint64(len(canotoTag_EpochInfo__SealingBlockSeq)) + canoto.SizeUint(c.SealingBlockSeq)
}
atomic.StoreUint64(&c.canotoData.size, size)
}
// CachedCanotoSize returns the previously calculated size of the Canoto
// representation from CalculateCanotoCache.
//
// If CalculateCanotoCache has not yet been called, it will return 0.
//
// If the struct has been modified since the last call to CalculateCanotoCache,
// the returned size may be incorrect.
func (c *EpochInfo) CachedCanotoSize() uint64 {
return atomic.LoadUint64(&c.canotoData.size)
}
// MarshalCanoto returns the Canoto representation of this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *EpochInfo) MarshalCanoto() []byte {
c.CalculateCanotoCache()
w := canoto.Writer{
B: make([]byte, 0, c.CachedCanotoSize()),
}
w = c.MarshalCanotoInto(w)
return w.B
}
// MarshalCanotoInto writes the struct into a [canoto.Writer] and returns the
// resulting [canoto.Writer]. Most users should just use MarshalCanoto.
//
// It is assumed that CalculateCanotoCache has been called since the last
// modification to this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *EpochInfo) MarshalCanotoInto(w canoto.Writer) canoto.Writer {
if !canoto.IsZero(c.PChainReferenceHeight) {
canoto.Append(&w, canotoTag_EpochInfo__PChainReferenceHeight)
canoto.AppendUint(&w, c.PChainReferenceHeight)
}
if !canoto.IsZero(c.EpochNumber) {
canoto.Append(&w, canotoTag_EpochInfo__EpochNumber)
canoto.AppendUint(&w, c.EpochNumber)
}
if !canoto.IsZero(c.PrevSealingBlockHash) {
canoto.Append(&w, canotoTag_EpochInfo__PrevSealingBlockHash)
canoto.AppendBytes(&w, (&c.PrevSealingBlockHash)[:])
}
if !canoto.IsZero(c.NextPChainReferenceHeight) {
canoto.Append(&w, canotoTag_EpochInfo__NextPChainReferenceHeight)
canoto.AppendUint(&w, c.NextPChainReferenceHeight)
}
if !canoto.IsZero(c.PrevVMBlockSeq) {
canoto.Append(&w, canotoTag_EpochInfo__PrevVMBlockSeq)
canoto.AppendUint(&w, c.PrevVMBlockSeq)
}
if c.BlockValidationDescriptor != nil {
fieldSize := (c.BlockValidationDescriptor).CachedCanotoSize()
canoto.Append(&w, canotoTag_EpochInfo__BlockValidationDescriptor)
canoto.AppendUint(&w, fieldSize)
w = (c.BlockValidationDescriptor).MarshalCanotoInto(w)
}
if c.NextEpochApprovals != nil {
fieldSize := (c.NextEpochApprovals).CachedCanotoSize()
canoto.Append(&w, canotoTag_EpochInfo__NextEpochApprovals)
canoto.AppendUint(&w, fieldSize)
w = (c.NextEpochApprovals).MarshalCanotoInto(w)
}
if !canoto.IsZero(c.SealingBlockSeq) {
canoto.Append(&w, canotoTag_EpochInfo__SealingBlockSeq)
canoto.AppendUint(&w, c.SealingBlockSeq)
}
return w
}
const (
canotoNumber_NodeBLSMapping__NodeID = 1
canotoNumber_NodeBLSMapping__BLSKey = 2
canotoNumber_NodeBLSMapping__Weight = 3
canotoTag_NodeBLSMapping__NodeID = "\x0a" // canoto.Tag(canotoNumber_NodeBLSMapping__NodeID, canoto.Len)
canotoTag_NodeBLSMapping__BLSKey = "\x12" // canoto.Tag(canotoNumber_NodeBLSMapping__BLSKey, canoto.Len)
canotoTag_NodeBLSMapping__Weight = "\x18" // canoto.Tag(canotoNumber_NodeBLSMapping__Weight, canoto.Varint)
)
type canotoData_NodeBLSMapping struct {
size uint64
}
// CanotoSpec returns the specification of this canoto message.
func (*NodeBLSMapping) CanotoSpec(...reflect.Type) *canoto.Spec {
var zero NodeBLSMapping
s := &canoto.Spec{
Name: "NodeBLSMapping",
Fields: []canoto.FieldType{
{
FieldNumber: canotoNumber_NodeBLSMapping__NodeID,
Name: "NodeID",
OneOf: "",
TypeFixedBytes: uint64(len(zero.NodeID)),
},
{
FieldNumber: canotoNumber_NodeBLSMapping__BLSKey,
Name: "BLSKey",
OneOf: "",
TypeBytes: true,
},
{
FieldNumber: canotoNumber_NodeBLSMapping__Weight,
Name: "Weight",
OneOf: "",
TypeUint: canoto.SizeOf(zero.Weight),
},
},
}
s.CalculateCanotoCache()
return s
}
// UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
//
// During parsing, the canoto cache is saved.
func (c *NodeBLSMapping) UnmarshalCanoto(bytes []byte) error {
r := canoto.Reader{
B: bytes,
}
return c.UnmarshalCanotoFrom(r)
}
// UnmarshalCanotoFrom populates the struct from a [canoto.Reader]. Most users
// should just use UnmarshalCanoto.
//
// During parsing, the canoto cache is saved.
//
// This function enables configuration of reader options.
func (c *NodeBLSMapping) UnmarshalCanotoFrom(r canoto.Reader) error {
// Zero the struct before unmarshaling.
*c = NodeBLSMapping{}
atomic.StoreUint64(&c.canotoData.size, uint64(len(r.B)))
var minField uint32
for canoto.HasNext(&r) {
field, wireType, err := canoto.ReadTag(&r)
if err != nil {
return err
}
if field < minField {
return canoto.ErrInvalidFieldOrder
}
switch field {
case canotoNumber_NodeBLSMapping__NodeID:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
const (
expectedLength = len(c.NodeID)
expectedLengthUint64 = uint64(expectedLength)
)
var length uint64
if err := canoto.ReadUint(&r, &length); err != nil {
return err
}
if length != expectedLengthUint64 {
return canoto.ErrInvalidLength
}
if expectedLength > len(r.B) {
return io.ErrUnexpectedEOF
}
copy((&c.NodeID)[:], r.B)
if canoto.IsZero(c.NodeID) {
return canoto.ErrZeroValue
}
r.B = r.B[expectedLength:]
case canotoNumber_NodeBLSMapping__BLSKey:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadBytes(&r, &c.BLSKey); err != nil {
return err
}
if len(c.BLSKey) == 0 {
return canoto.ErrZeroValue
}
case canotoNumber_NodeBLSMapping__Weight:
if wireType != canoto.Varint {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadUint(&r, &c.Weight); err != nil {
return err
}
if canoto.IsZero(c.Weight) {
return canoto.ErrZeroValue
}
default:
return canoto.ErrUnknownField
}
minField = field + 1
}
return nil
}
// ValidCanoto validates that the struct can be correctly marshaled into the
// Canoto format.
//
// Specifically, ValidCanoto ensures:
// 1. All OneOfs are specified at most once.
// 2. All strings are valid utf-8.
// 3. All custom fields are ValidCanoto.
func (c *NodeBLSMapping) ValidCanoto() bool {
return true
}
// CalculateCanotoCache populates size and OneOf caches based on the current
// values in the struct.
//
// It is not safe to copy this struct concurrently.
func (c *NodeBLSMapping) CalculateCanotoCache() {
var size uint64
if !canoto.IsZero(c.NodeID) {
size += uint64(len(canotoTag_NodeBLSMapping__NodeID)) + canoto.SizeBytes((&c.NodeID)[:])
}
if len(c.BLSKey) != 0 {
size += uint64(len(canotoTag_NodeBLSMapping__BLSKey)) + canoto.SizeBytes(c.BLSKey)
}
if !canoto.IsZero(c.Weight) {
size += uint64(len(canotoTag_NodeBLSMapping__Weight)) + canoto.SizeUint(c.Weight)
}
atomic.StoreUint64(&c.canotoData.size, size)
}
// CachedCanotoSize returns the previously calculated size of the Canoto
// representation from CalculateCanotoCache.
//
// If CalculateCanotoCache has not yet been called, it will return 0.
//
// If the struct has been modified since the last call to CalculateCanotoCache,
// the returned size may be incorrect.
func (c *NodeBLSMapping) CachedCanotoSize() uint64 {
return atomic.LoadUint64(&c.canotoData.size)
}
// MarshalCanoto returns the Canoto representation of this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *NodeBLSMapping) MarshalCanoto() []byte {
c.CalculateCanotoCache()
w := canoto.Writer{
B: make([]byte, 0, c.CachedCanotoSize()),
}
w = c.MarshalCanotoInto(w)
return w.B
}
// MarshalCanotoInto writes the struct into a [canoto.Writer] and returns the
// resulting [canoto.Writer]. Most users should just use MarshalCanoto.
//
// It is assumed that CalculateCanotoCache has been called since the last
// modification to this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *NodeBLSMapping) MarshalCanotoInto(w canoto.Writer) canoto.Writer {
if !canoto.IsZero(c.NodeID) {
canoto.Append(&w, canotoTag_NodeBLSMapping__NodeID)
canoto.AppendBytes(&w, (&c.NodeID)[:])
}
if len(c.BLSKey) != 0 {
canoto.Append(&w, canotoTag_NodeBLSMapping__BLSKey)
canoto.AppendBytes(&w, c.BLSKey)
}
if !canoto.IsZero(c.Weight) {
canoto.Append(&w, canotoTag_NodeBLSMapping__Weight)
canoto.AppendUint(&w, c.Weight)
}
return w
}
const (
canotoNumber_BlockValidationDescriptor__AggregatedMembership = 1
canotoTag_BlockValidationDescriptor__AggregatedMembership = "\x0a" // canoto.Tag(canotoNumber_BlockValidationDescriptor__AggregatedMembership, canoto.Len)
)
type canotoData_BlockValidationDescriptor struct {
size uint64
}
// CanotoSpec returns the specification of this canoto message.
func (*BlockValidationDescriptor) CanotoSpec(types ...reflect.Type) *canoto.Spec {
types = append(types, reflect.TypeFor[BlockValidationDescriptor]())
var zero BlockValidationDescriptor
s := &canoto.Spec{
Name: "BlockValidationDescriptor",
Fields: []canoto.FieldType{
canoto.FieldTypeFromField(
/*type inference:*/ (&zero.AggregatedMembership),
/*FieldNumber: */ canotoNumber_BlockValidationDescriptor__AggregatedMembership,
/*Name: */ "AggregatedMembership",
/*FixedLength: */ 0,
/*Repeated: */ false,
/*OneOf: */ "",
/*Pointer: */ false,
/*types: */ types,
),
},
}
s.CalculateCanotoCache()
return s
}
// UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
//
// During parsing, the canoto cache is saved.
func (c *BlockValidationDescriptor) UnmarshalCanoto(bytes []byte) error {
r := canoto.Reader{
B: bytes,
}
return c.UnmarshalCanotoFrom(r)
}
// UnmarshalCanotoFrom populates the struct from a [canoto.Reader]. Most users
// should just use UnmarshalCanoto.
//
// During parsing, the canoto cache is saved.
//
// This function enables configuration of reader options.
func (c *BlockValidationDescriptor) UnmarshalCanotoFrom(r canoto.Reader) error {
// Zero the struct before unmarshaling.
*c = BlockValidationDescriptor{}
atomic.StoreUint64(&c.canotoData.size, uint64(len(r.B)))
var minField uint32
for canoto.HasNext(&r) {
field, wireType, err := canoto.ReadTag(&r)
if err != nil {
return err
}
if field < minField {
return canoto.ErrInvalidFieldOrder
}
switch field {
case canotoNumber_BlockValidationDescriptor__AggregatedMembership:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
// Read the bytes for the field.
originalUnsafe := r.Unsafe
r.Unsafe = true
var msgBytes []byte
if err := canoto.ReadBytes(&r, &msgBytes); err != nil {
return err
}
if len(msgBytes) == 0 {
return canoto.ErrZeroValue
}
r.Unsafe = originalUnsafe
// Unmarshal the field from the bytes.
remainingBytes := r.B
r.B = msgBytes
if err := (&c.AggregatedMembership).UnmarshalCanotoFrom(r); err != nil {
return err
}
r.B = remainingBytes
default:
return canoto.ErrUnknownField
}
minField = field + 1
}
return nil
}
// ValidCanoto validates that the struct can be correctly marshaled into the
// Canoto format.
//
// Specifically, ValidCanoto ensures:
// 1. All OneOfs are specified at most once.
// 2. All strings are valid utf-8.
// 3. All custom fields are ValidCanoto.
func (c *BlockValidationDescriptor) ValidCanoto() bool {
if !(&c.AggregatedMembership).ValidCanoto() {
return false
}
return true
}
// CalculateCanotoCache populates size and OneOf caches based on the current
// values in the struct.
//
// It is not safe to copy this struct concurrently.
func (c *BlockValidationDescriptor) CalculateCanotoCache() {
var size uint64
(&c.AggregatedMembership).CalculateCanotoCache()
if fieldSize := (&c.AggregatedMembership).CachedCanotoSize(); fieldSize != 0 {
size += uint64(len(canotoTag_BlockValidationDescriptor__AggregatedMembership)) + canoto.SizeUint(fieldSize) + fieldSize
}
atomic.StoreUint64(&c.canotoData.size, size)
}
// CachedCanotoSize returns the previously calculated size of the Canoto
// representation from CalculateCanotoCache.
//
// If CalculateCanotoCache has not yet been called, it will return 0.
//
// If the struct has been modified since the last call to CalculateCanotoCache,
// the returned size may be incorrect.
func (c *BlockValidationDescriptor) CachedCanotoSize() uint64 {
return atomic.LoadUint64(&c.canotoData.size)
}
// MarshalCanoto returns the Canoto representation of this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *BlockValidationDescriptor) MarshalCanoto() []byte {
c.CalculateCanotoCache()
w := canoto.Writer{
B: make([]byte, 0, c.CachedCanotoSize()),
}
w = c.MarshalCanotoInto(w)
return w.B
}
// MarshalCanotoInto writes the struct into a [canoto.Writer] and returns the
// resulting [canoto.Writer]. Most users should just use MarshalCanoto.
//
// It is assumed that CalculateCanotoCache has been called since the last
// modification to this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *BlockValidationDescriptor) MarshalCanotoInto(w canoto.Writer) canoto.Writer {
if fieldSize := (&c.AggregatedMembership).CachedCanotoSize(); fieldSize != 0 {
canoto.Append(&w, canotoTag_BlockValidationDescriptor__AggregatedMembership)
canoto.AppendUint(&w, fieldSize)
w = (&c.AggregatedMembership).MarshalCanotoInto(w)
}
return w
}
const (
canotoNumber_AggregatedMembership__Members = 1
canotoTag_AggregatedMembership__Members = "\x0a" // canoto.Tag(canotoNumber_AggregatedMembership__Members, canoto.Len)
)
type canotoData_AggregatedMembership struct {
size uint64
}
// CanotoSpec returns the specification of this canoto message.
func (*AggregatedMembership) CanotoSpec(types ...reflect.Type) *canoto.Spec {
types = append(types, reflect.TypeFor[AggregatedMembership]())
var zero AggregatedMembership
s := &canoto.Spec{
Name: "AggregatedMembership",
Fields: []canoto.FieldType{
canoto.FieldTypeFromField(
/*type inference:*/ (canoto.MakeEntryNilPointer(zero.Members)),
/*FieldNumber: */ canotoNumber_AggregatedMembership__Members,
/*Name: */ "Members",
/*FixedLength: */ 0,
/*Repeated: */ true,
/*OneOf: */ "",
/*Pointer: */ false,
/*types: */ types,
),
},
}
s.CalculateCanotoCache()
return s
}
// UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
//
// During parsing, the canoto cache is saved.
func (c *AggregatedMembership) UnmarshalCanoto(bytes []byte) error {
r := canoto.Reader{
B: bytes,
}
return c.UnmarshalCanotoFrom(r)
}
// UnmarshalCanotoFrom populates the struct from a [canoto.Reader]. Most users
// should just use UnmarshalCanoto.
//
// During parsing, the canoto cache is saved.
//
// This function enables configuration of reader options.
func (c *AggregatedMembership) UnmarshalCanotoFrom(r canoto.Reader) error {
// Zero the struct before unmarshaling.
*c = AggregatedMembership{}
atomic.StoreUint64(&c.canotoData.size, uint64(len(r.B)))
var minField uint32
for canoto.HasNext(&r) {
field, wireType, err := canoto.ReadTag(&r)
if err != nil {
return err
}
if field < minField {
return canoto.ErrInvalidFieldOrder
}
switch field {
case canotoNumber_AggregatedMembership__Members:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
// Read the first entry manually because the tag is already
// stripped.
originalUnsafe := r.Unsafe
r.Unsafe = true
var msgBytes []byte
if err := canoto.ReadBytes(&r, &msgBytes); err != nil {
return err
}
r.Unsafe = originalUnsafe
// Count the number of additional entries after the first entry.
countMinus1, err := canoto.CountBytes(r.B, canotoTag_AggregatedMembership__Members)
if err != nil {
return err
}
c.Members = canoto.MakeSlice(c.Members, countMinus1+1)
field := c.Members
additionalField := field[1:]
if len(msgBytes) != 0 {
remainingBytes := r.B
r.B = msgBytes
if err := (&field[0]).UnmarshalCanotoFrom(r); err != nil {
return err
}
r.B = remainingBytes
}
// Read the rest of the entries, stripping the tag each time.
for i := range additionalField {
r.B = r.B[len(canotoTag_AggregatedMembership__Members):]
r.Unsafe = true
if err := canoto.ReadBytes(&r, &msgBytes); err != nil {
return err
}
r.Unsafe = originalUnsafe
if len(msgBytes) == 0 {
continue
}
remainingBytes := r.B
r.B = msgBytes
if err := (&additionalField[i]).UnmarshalCanotoFrom(r); err != nil {
return err
}
r.B = remainingBytes
}
default:
return canoto.ErrUnknownField
}
minField = field + 1
}
return nil
}
// ValidCanoto validates that the struct can be correctly marshaled into the
// Canoto format.
//
// Specifically, ValidCanoto ensures:
// 1. All OneOfs are specified at most once.
// 2. All strings are valid utf-8.
// 3. All custom fields are ValidCanoto.
func (c *AggregatedMembership) ValidCanoto() bool {
{
field := c.Members
for i := range field {
if !(&field[i]).ValidCanoto() {
return false
}
}
}
return true
}
// CalculateCanotoCache populates size and OneOf caches based on the current
// values in the struct.
//
// It is not safe to copy this struct concurrently.
func (c *AggregatedMembership) CalculateCanotoCache() {
var size uint64
{
field := c.Members
for i := range field {
(&field[i]).CalculateCanotoCache()
fieldSize := (&field[i]).CachedCanotoSize()
size += uint64(len(canotoTag_AggregatedMembership__Members)) + canoto.SizeUint(fieldSize) + fieldSize
}
}
atomic.StoreUint64(&c.canotoData.size, size)
}
// CachedCanotoSize returns the previously calculated size of the Canoto
// representation from CalculateCanotoCache.
//
// If CalculateCanotoCache has not yet been called, it will return 0.
//
// If the struct has been modified since the last call to CalculateCanotoCache,
// the returned size may be incorrect.
func (c *AggregatedMembership) CachedCanotoSize() uint64 {
return atomic.LoadUint64(&c.canotoData.size)
}
// MarshalCanoto returns the Canoto representation of this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *AggregatedMembership) MarshalCanoto() []byte {
c.CalculateCanotoCache()
w := canoto.Writer{
B: make([]byte, 0, c.CachedCanotoSize()),
}
w = c.MarshalCanotoInto(w)
return w.B
}
// MarshalCanotoInto writes the struct into a [canoto.Writer] and returns the
// resulting [canoto.Writer]. Most users should just use MarshalCanoto.
//
// It is assumed that CalculateCanotoCache has been called since the last
// modification to this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *AggregatedMembership) MarshalCanotoInto(w canoto.Writer) canoto.Writer {
{
field := c.Members
for i := range field {
canoto.Append(&w, canotoTag_AggregatedMembership__Members)
canoto.AppendUint(&w, (&field[i]).CachedCanotoSize())
w = (&field[i]).MarshalCanotoInto(w)
}
}
return w
}
const (
canotoNumber_NextEpochApprovals__NodeIDs = 1
canotoNumber_NextEpochApprovals__Signature = 2
canotoTag_NextEpochApprovals__NodeIDs = "\x0a" // canoto.Tag(canotoNumber_NextEpochApprovals__NodeIDs, canoto.Len)
canotoTag_NextEpochApprovals__Signature = "\x12" // canoto.Tag(canotoNumber_NextEpochApprovals__Signature, canoto.Len)
)
type canotoData_NextEpochApprovals struct {
size uint64
}
// CanotoSpec returns the specification of this canoto message.
func (*NextEpochApprovals) CanotoSpec(...reflect.Type) *canoto.Spec {
s := &canoto.Spec{
Name: "NextEpochApprovals",
Fields: []canoto.FieldType{
{
FieldNumber: canotoNumber_NextEpochApprovals__NodeIDs,
Name: "NodeIDs",
OneOf: "",
TypeBytes: true,
},
{
FieldNumber: canotoNumber_NextEpochApprovals__Signature,
Name: "Signature",
OneOf: "",
TypeBytes: true,
},
},
}
s.CalculateCanotoCache()
return s
}
// UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
//
// During parsing, the canoto cache is saved.
func (c *NextEpochApprovals) UnmarshalCanoto(bytes []byte) error {
r := canoto.Reader{
B: bytes,
}
return c.UnmarshalCanotoFrom(r)
}
// UnmarshalCanotoFrom populates the struct from a [canoto.Reader]. Most users
// should just use UnmarshalCanoto.
//
// During parsing, the canoto cache is saved.
//
// This function enables configuration of reader options.
func (c *NextEpochApprovals) UnmarshalCanotoFrom(r canoto.Reader) error {
// Zero the struct before unmarshaling.
*c = NextEpochApprovals{}
atomic.StoreUint64(&c.canotoData.size, uint64(len(r.B)))
var minField uint32
for canoto.HasNext(&r) {
field, wireType, err := canoto.ReadTag(&r)
if err != nil {
return err
}
if field < minField {
return canoto.ErrInvalidFieldOrder
}
switch field {
case canotoNumber_NextEpochApprovals__NodeIDs:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadBytes(&r, &c.NodeIDs); err != nil {
return err
}
if len(c.NodeIDs) == 0 {
return canoto.ErrZeroValue
}
case canotoNumber_NextEpochApprovals__Signature:
if wireType != canoto.Len {
return canoto.ErrUnexpectedWireType
}
if err := canoto.ReadBytes(&r, &c.Signature); err != nil {
return err
}
if len(c.Signature) == 0 {
return canoto.ErrZeroValue
}
default:
return canoto.ErrUnknownField
}
minField = field + 1
}
return nil
}
// ValidCanoto validates that the struct can be correctly marshaled into the
// Canoto format.
//
// Specifically, ValidCanoto ensures:
// 1. All OneOfs are specified at most once.
// 2. All strings are valid utf-8.
// 3. All custom fields are ValidCanoto.
func (c *NextEpochApprovals) ValidCanoto() bool {
return true
}
// CalculateCanotoCache populates size and OneOf caches based on the current
// values in the struct.
//
// It is not safe to copy this struct concurrently.
func (c *NextEpochApprovals) CalculateCanotoCache() {
var size uint64
if len(c.NodeIDs) != 0 {
size += uint64(len(canotoTag_NextEpochApprovals__NodeIDs)) + canoto.SizeBytes(c.NodeIDs)
}
if len(c.Signature) != 0 {
size += uint64(len(canotoTag_NextEpochApprovals__Signature)) + canoto.SizeBytes(c.Signature)
}
atomic.StoreUint64(&c.canotoData.size, size)
}
// CachedCanotoSize returns the previously calculated size of the Canoto
// representation from CalculateCanotoCache.
//
// If CalculateCanotoCache has not yet been called, it will return 0.
//
// If the struct has been modified since the last call to CalculateCanotoCache,
// the returned size may be incorrect.
func (c *NextEpochApprovals) CachedCanotoSize() uint64 {
return atomic.LoadUint64(&c.canotoData.size)
}
// MarshalCanoto returns the Canoto representation of this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *NextEpochApprovals) MarshalCanoto() []byte {
c.CalculateCanotoCache()
w := canoto.Writer{
B: make([]byte, 0, c.CachedCanotoSize()),
}
w = c.MarshalCanotoInto(w)
return w.B
}
// MarshalCanotoInto writes the struct into a [canoto.Writer] and returns the
// resulting [canoto.Writer]. Most users should just use MarshalCanoto.
//
// It is assumed that CalculateCanotoCache has been called since the last
// modification to this struct.
//
// It is assumed that this struct is ValidCanoto.
//
// It is not safe to copy this struct concurrently.
func (c *NextEpochApprovals) MarshalCanotoInto(w canoto.Writer) canoto.Writer {
if len(c.NodeIDs) != 0 {
canoto.Append(&w, canotoTag_NextEpochApprovals__NodeIDs)
canoto.AppendBytes(&w, c.NodeIDs)
}
if len(c.Signature) != 0 {
canoto.Append(&w, canotoTag_NextEpochApprovals__Signature)
canoto.AppendBytes(&w, c.Signature)
}
return w
}