mirror of
https://github.com/luxfi/bft.git
synced 2026-10-30 17:01:54 +00:00
766 lines
21 KiB
Go
766 lines
21 KiB
Go
// Code generated by canoto. DO NOT EDIT.
|
|
// versions:
|
|
// canoto v0.19.0
|
|
// source: blacklist.go
|
|
|
|
package common
|
|
|
|
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_Blacklist__NodeCount = 1
|
|
canotoNumber_Blacklist__SuspectedNodes = 2
|
|
canotoNumber_Blacklist__Updates = 3
|
|
|
|
canotoTag_Blacklist__NodeCount = "\x08" // canoto.Tag(canotoNumber_Blacklist__NodeCount, canoto.Varint)
|
|
canotoTag_Blacklist__SuspectedNodes = "\x12" // canoto.Tag(canotoNumber_Blacklist__SuspectedNodes, canoto.Len)
|
|
canotoTag_Blacklist__Updates = "\x1a" // canoto.Tag(canotoNumber_Blacklist__Updates, canoto.Len)
|
|
)
|
|
|
|
type canotoData_Blacklist struct {
|
|
size uint64
|
|
}
|
|
|
|
// CanotoSpec returns the specification of this canoto message.
|
|
func (*Blacklist) CanotoSpec(types ...reflect.Type) *canoto.Spec {
|
|
types = append(types, reflect.TypeFor[Blacklist]())
|
|
var zero Blacklist
|
|
s := &canoto.Spec{
|
|
Name: "Blacklist",
|
|
Fields: []canoto.FieldType{
|
|
{
|
|
FieldNumber: canotoNumber_Blacklist__NodeCount,
|
|
Name: "NodeCount",
|
|
OneOf: "",
|
|
TypeUint: canoto.SizeOf(zero.NodeCount),
|
|
},
|
|
canoto.FieldTypeFromField(
|
|
/*type inference:*/ (canoto.MakeEntryNilPointer(zero.SuspectedNodes)),
|
|
/*FieldNumber: */ canotoNumber_Blacklist__SuspectedNodes,
|
|
/*Name: */ "SuspectedNodes",
|
|
/*FixedLength: */ 0,
|
|
/*Repeated: */ true,
|
|
/*OneOf: */ "",
|
|
/*Pointer: */ false,
|
|
/*types: */ types,
|
|
),
|
|
canoto.FieldTypeFromField(
|
|
/*type inference:*/ (canoto.MakeEntryNilPointer(zero.Updates)),
|
|
/*FieldNumber: */ canotoNumber_Blacklist__Updates,
|
|
/*Name: */ "Updates",
|
|
/*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 *Blacklist) 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 *Blacklist) UnmarshalCanotoFrom(r canoto.Reader) error {
|
|
// Zero the struct before unmarshaling.
|
|
*c = Blacklist{}
|
|
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_Blacklist__NodeCount:
|
|
if wireType != canoto.Varint {
|
|
return canoto.ErrUnexpectedWireType
|
|
}
|
|
|
|
if err := canoto.ReadUint(&r, &c.NodeCount); err != nil {
|
|
return err
|
|
}
|
|
if canoto.IsZero(c.NodeCount) {
|
|
return canoto.ErrZeroValue
|
|
}
|
|
case canotoNumber_Blacklist__SuspectedNodes:
|
|
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_Blacklist__SuspectedNodes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.SuspectedNodes = canoto.MakeSlice(c.SuspectedNodes, countMinus1+1)
|
|
field := c.SuspectedNodes
|
|
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_Blacklist__SuspectedNodes):]
|
|
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
|
|
}
|
|
case canotoNumber_Blacklist__Updates:
|
|
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_Blacklist__Updates)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.Updates = canoto.MakeSlice(c.Updates, countMinus1+1)
|
|
field := c.Updates
|
|
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_Blacklist__Updates):]
|
|
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 *Blacklist) ValidCanoto() bool {
|
|
{
|
|
field := c.SuspectedNodes
|
|
for i := range field {
|
|
if !(&field[i]).ValidCanoto() {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
{
|
|
field := c.Updates
|
|
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 *Blacklist) CalculateCanotoCache() {
|
|
var size uint64
|
|
if !canoto.IsZero(c.NodeCount) {
|
|
size += uint64(len(canotoTag_Blacklist__NodeCount)) + canoto.SizeUint(c.NodeCount)
|
|
}
|
|
{
|
|
field := c.SuspectedNodes
|
|
for i := range field {
|
|
(&field[i]).CalculateCanotoCache()
|
|
fieldSize := (&field[i]).CachedCanotoSize()
|
|
size += uint64(len(canotoTag_Blacklist__SuspectedNodes)) + canoto.SizeUint(fieldSize) + fieldSize
|
|
}
|
|
}
|
|
{
|
|
field := c.Updates
|
|
for i := range field {
|
|
(&field[i]).CalculateCanotoCache()
|
|
fieldSize := (&field[i]).CachedCanotoSize()
|
|
size += uint64(len(canotoTag_Blacklist__Updates)) + 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 *Blacklist) 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 *Blacklist) 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 *Blacklist) MarshalCanotoInto(w canoto.Writer) canoto.Writer {
|
|
if !canoto.IsZero(c.NodeCount) {
|
|
canoto.Append(&w, canotoTag_Blacklist__NodeCount)
|
|
canoto.AppendUint(&w, c.NodeCount)
|
|
}
|
|
{
|
|
field := c.SuspectedNodes
|
|
for i := range field {
|
|
canoto.Append(&w, canotoTag_Blacklist__SuspectedNodes)
|
|
canoto.AppendUint(&w, (&field[i]).CachedCanotoSize())
|
|
w = (&field[i]).MarshalCanotoInto(w)
|
|
}
|
|
}
|
|
{
|
|
field := c.Updates
|
|
for i := range field {
|
|
canoto.Append(&w, canotoTag_Blacklist__Updates)
|
|
canoto.AppendUint(&w, (&field[i]).CachedCanotoSize())
|
|
w = (&field[i]).MarshalCanotoInto(w)
|
|
}
|
|
}
|
|
return w
|
|
}
|
|
|
|
const (
|
|
canotoNumber_BlacklistUpdate__Type = 1
|
|
canotoNumber_BlacklistUpdate__NodeIndex = 2
|
|
|
|
canotoTag_BlacklistUpdate__Type = "\x08" // canoto.Tag(canotoNumber_BlacklistUpdate__Type, canoto.Varint)
|
|
canotoTag_BlacklistUpdate__NodeIndex = "\x10" // canoto.Tag(canotoNumber_BlacklistUpdate__NodeIndex, canoto.Varint)
|
|
)
|
|
|
|
type canotoData_BlacklistUpdate struct {
|
|
size uint64
|
|
}
|
|
|
|
// CanotoSpec returns the specification of this canoto message.
|
|
func (*BlacklistUpdate) CanotoSpec(...reflect.Type) *canoto.Spec {
|
|
var zero BlacklistUpdate
|
|
s := &canoto.Spec{
|
|
Name: "BlacklistUpdate",
|
|
Fields: []canoto.FieldType{
|
|
{
|
|
FieldNumber: canotoNumber_BlacklistUpdate__Type,
|
|
Name: "Type",
|
|
OneOf: "",
|
|
TypeUint: canoto.SizeOf(zero.Type),
|
|
},
|
|
{
|
|
FieldNumber: canotoNumber_BlacklistUpdate__NodeIndex,
|
|
Name: "NodeIndex",
|
|
OneOf: "",
|
|
TypeUint: canoto.SizeOf(zero.NodeIndex),
|
|
},
|
|
},
|
|
}
|
|
s.CalculateCanotoCache()
|
|
return s
|
|
}
|
|
|
|
// UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
|
|
//
|
|
// During parsing, the canoto cache is saved.
|
|
func (c *BlacklistUpdate) 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 *BlacklistUpdate) UnmarshalCanotoFrom(r canoto.Reader) error {
|
|
// Zero the struct before unmarshaling.
|
|
*c = BlacklistUpdate{}
|
|
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_BlacklistUpdate__Type:
|
|
if wireType != canoto.Varint {
|
|
return canoto.ErrUnexpectedWireType
|
|
}
|
|
|
|
if err := canoto.ReadUint(&r, &c.Type); err != nil {
|
|
return err
|
|
}
|
|
if canoto.IsZero(c.Type) {
|
|
return canoto.ErrZeroValue
|
|
}
|
|
case canotoNumber_BlacklistUpdate__NodeIndex:
|
|
if wireType != canoto.Varint {
|
|
return canoto.ErrUnexpectedWireType
|
|
}
|
|
|
|
if err := canoto.ReadUint(&r, &c.NodeIndex); err != nil {
|
|
return err
|
|
}
|
|
if canoto.IsZero(c.NodeIndex) {
|
|
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 *BlacklistUpdate) 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 *BlacklistUpdate) CalculateCanotoCache() {
|
|
var size uint64
|
|
if !canoto.IsZero(c.Type) {
|
|
size += uint64(len(canotoTag_BlacklistUpdate__Type)) + canoto.SizeUint(c.Type)
|
|
}
|
|
if !canoto.IsZero(c.NodeIndex) {
|
|
size += uint64(len(canotoTag_BlacklistUpdate__NodeIndex)) + canoto.SizeUint(c.NodeIndex)
|
|
}
|
|
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 *BlacklistUpdate) 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 *BlacklistUpdate) 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 *BlacklistUpdate) MarshalCanotoInto(w canoto.Writer) canoto.Writer {
|
|
if !canoto.IsZero(c.Type) {
|
|
canoto.Append(&w, canotoTag_BlacklistUpdate__Type)
|
|
canoto.AppendUint(&w, c.Type)
|
|
}
|
|
if !canoto.IsZero(c.NodeIndex) {
|
|
canoto.Append(&w, canotoTag_BlacklistUpdate__NodeIndex)
|
|
canoto.AppendUint(&w, c.NodeIndex)
|
|
}
|
|
return w
|
|
}
|
|
|
|
const (
|
|
canotoNumber_SuspectedNode__NodeIndex = 1
|
|
canotoNumber_SuspectedNode__SuspectingCount = 2
|
|
canotoNumber_SuspectedNode__RedeemingCount = 3
|
|
canotoNumber_SuspectedNode__OrbitSuspected = 4
|
|
canotoNumber_SuspectedNode__OrbitToRedeem = 5
|
|
|
|
canotoTag_SuspectedNode__NodeIndex = "\x08" // canoto.Tag(canotoNumber_SuspectedNode__NodeIndex, canoto.Varint)
|
|
canotoTag_SuspectedNode__SuspectingCount = "\x10" // canoto.Tag(canotoNumber_SuspectedNode__SuspectingCount, canoto.Varint)
|
|
canotoTag_SuspectedNode__RedeemingCount = "\x18" // canoto.Tag(canotoNumber_SuspectedNode__RedeemingCount, canoto.Varint)
|
|
canotoTag_SuspectedNode__OrbitSuspected = "\x20" // canoto.Tag(canotoNumber_SuspectedNode__OrbitSuspected, canoto.Varint)
|
|
canotoTag_SuspectedNode__OrbitToRedeem = "\x28" // canoto.Tag(canotoNumber_SuspectedNode__OrbitToRedeem, canoto.Varint)
|
|
)
|
|
|
|
type canotoData_SuspectedNode struct {
|
|
size uint64
|
|
}
|
|
|
|
// CanotoSpec returns the specification of this canoto message.
|
|
func (*SuspectedNode) CanotoSpec(...reflect.Type) *canoto.Spec {
|
|
var zero SuspectedNode
|
|
s := &canoto.Spec{
|
|
Name: "SuspectedNode",
|
|
Fields: []canoto.FieldType{
|
|
{
|
|
FieldNumber: canotoNumber_SuspectedNode__NodeIndex,
|
|
Name: "NodeIndex",
|
|
OneOf: "",
|
|
TypeUint: canoto.SizeOf(zero.NodeIndex),
|
|
},
|
|
{
|
|
FieldNumber: canotoNumber_SuspectedNode__SuspectingCount,
|
|
Name: "SuspectingCount",
|
|
OneOf: "",
|
|
TypeUint: canoto.SizeOf(zero.SuspectingCount),
|
|
},
|
|
{
|
|
FieldNumber: canotoNumber_SuspectedNode__RedeemingCount,
|
|
Name: "RedeemingCount",
|
|
OneOf: "",
|
|
TypeUint: canoto.SizeOf(zero.RedeemingCount),
|
|
},
|
|
{
|
|
FieldNumber: canotoNumber_SuspectedNode__OrbitSuspected,
|
|
Name: "OrbitSuspected",
|
|
OneOf: "",
|
|
TypeUint: canoto.SizeOf(zero.OrbitSuspected),
|
|
},
|
|
{
|
|
FieldNumber: canotoNumber_SuspectedNode__OrbitToRedeem,
|
|
Name: "OrbitToRedeem",
|
|
OneOf: "",
|
|
TypeUint: canoto.SizeOf(zero.OrbitToRedeem),
|
|
},
|
|
},
|
|
}
|
|
s.CalculateCanotoCache()
|
|
return s
|
|
}
|
|
|
|
// UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
|
|
//
|
|
// During parsing, the canoto cache is saved.
|
|
func (c *SuspectedNode) 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 *SuspectedNode) UnmarshalCanotoFrom(r canoto.Reader) error {
|
|
// Zero the struct before unmarshaling.
|
|
*c = SuspectedNode{}
|
|
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_SuspectedNode__NodeIndex:
|
|
if wireType != canoto.Varint {
|
|
return canoto.ErrUnexpectedWireType
|
|
}
|
|
|
|
if err := canoto.ReadUint(&r, &c.NodeIndex); err != nil {
|
|
return err
|
|
}
|
|
if canoto.IsZero(c.NodeIndex) {
|
|
return canoto.ErrZeroValue
|
|
}
|
|
case canotoNumber_SuspectedNode__SuspectingCount:
|
|
if wireType != canoto.Varint {
|
|
return canoto.ErrUnexpectedWireType
|
|
}
|
|
|
|
if err := canoto.ReadUint(&r, &c.SuspectingCount); err != nil {
|
|
return err
|
|
}
|
|
if canoto.IsZero(c.SuspectingCount) {
|
|
return canoto.ErrZeroValue
|
|
}
|
|
case canotoNumber_SuspectedNode__RedeemingCount:
|
|
if wireType != canoto.Varint {
|
|
return canoto.ErrUnexpectedWireType
|
|
}
|
|
|
|
if err := canoto.ReadUint(&r, &c.RedeemingCount); err != nil {
|
|
return err
|
|
}
|
|
if canoto.IsZero(c.RedeemingCount) {
|
|
return canoto.ErrZeroValue
|
|
}
|
|
case canotoNumber_SuspectedNode__OrbitSuspected:
|
|
if wireType != canoto.Varint {
|
|
return canoto.ErrUnexpectedWireType
|
|
}
|
|
|
|
if err := canoto.ReadUint(&r, &c.OrbitSuspected); err != nil {
|
|
return err
|
|
}
|
|
if canoto.IsZero(c.OrbitSuspected) {
|
|
return canoto.ErrZeroValue
|
|
}
|
|
case canotoNumber_SuspectedNode__OrbitToRedeem:
|
|
if wireType != canoto.Varint {
|
|
return canoto.ErrUnexpectedWireType
|
|
}
|
|
|
|
if err := canoto.ReadUint(&r, &c.OrbitToRedeem); err != nil {
|
|
return err
|
|
}
|
|
if canoto.IsZero(c.OrbitToRedeem) {
|
|
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 *SuspectedNode) 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 *SuspectedNode) CalculateCanotoCache() {
|
|
var size uint64
|
|
if !canoto.IsZero(c.NodeIndex) {
|
|
size += uint64(len(canotoTag_SuspectedNode__NodeIndex)) + canoto.SizeUint(c.NodeIndex)
|
|
}
|
|
if !canoto.IsZero(c.SuspectingCount) {
|
|
size += uint64(len(canotoTag_SuspectedNode__SuspectingCount)) + canoto.SizeUint(c.SuspectingCount)
|
|
}
|
|
if !canoto.IsZero(c.RedeemingCount) {
|
|
size += uint64(len(canotoTag_SuspectedNode__RedeemingCount)) + canoto.SizeUint(c.RedeemingCount)
|
|
}
|
|
if !canoto.IsZero(c.OrbitSuspected) {
|
|
size += uint64(len(canotoTag_SuspectedNode__OrbitSuspected)) + canoto.SizeUint(c.OrbitSuspected)
|
|
}
|
|
if !canoto.IsZero(c.OrbitToRedeem) {
|
|
size += uint64(len(canotoTag_SuspectedNode__OrbitToRedeem)) + canoto.SizeUint(c.OrbitToRedeem)
|
|
}
|
|
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 *SuspectedNode) 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 *SuspectedNode) 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 *SuspectedNode) MarshalCanotoInto(w canoto.Writer) canoto.Writer {
|
|
if !canoto.IsZero(c.NodeIndex) {
|
|
canoto.Append(&w, canotoTag_SuspectedNode__NodeIndex)
|
|
canoto.AppendUint(&w, c.NodeIndex)
|
|
}
|
|
if !canoto.IsZero(c.SuspectingCount) {
|
|
canoto.Append(&w, canotoTag_SuspectedNode__SuspectingCount)
|
|
canoto.AppendUint(&w, c.SuspectingCount)
|
|
}
|
|
if !canoto.IsZero(c.RedeemingCount) {
|
|
canoto.Append(&w, canotoTag_SuspectedNode__RedeemingCount)
|
|
canoto.AppendUint(&w, c.RedeemingCount)
|
|
}
|
|
if !canoto.IsZero(c.OrbitSuspected) {
|
|
canoto.Append(&w, canotoTag_SuspectedNode__OrbitSuspected)
|
|
canoto.AppendUint(&w, c.OrbitSuspected)
|
|
}
|
|
if !canoto.IsZero(c.OrbitToRedeem) {
|
|
canoto.Append(&w, canotoTag_SuspectedNode__OrbitToRedeem)
|
|
canoto.AppendUint(&w, c.OrbitToRedeem)
|
|
}
|
|
return w
|
|
}
|