mirror of
https://github.com/luxfi/zap.git
synced 2026-10-30 15:04:16 +00:00
There is one perfected typed ZAP layer and it lives at github.com/luxfi/zap/v1 — forwards-only, no backwards-compat baggage, never a breaking major. Mechanical, behavior-preserving: v2/ -> v1/ (git mv), package zapv2 -> zapv1, import path .../zap/v2 -> .../zap/v1 (incl. the codegen's emitted banner + import so generated files reference /v1). Codegen golden tests pass; typed layer vets clean. (Pre-existing CGO 'resolv' link failures in the root package are unrelated env noise.)
157 lines
6.5 KiB
Go
157 lines
6.5 KiB
Go
// Copyright (C) 2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
//
|
|
// Code generated by github.com/luxfi/zap/v1/codegen — DO NOT EDIT.
|
|
// Source schema: QuasarCert (kind=0x01, size=72).
|
|
|
|
package consensuswire
|
|
|
|
import (
|
|
"github.com/luxfi/zap"
|
|
zapv1 "github.com/luxfi/zap/v1"
|
|
)
|
|
|
|
// KindQuasarCert is the wire discriminator for QuasarCert.
|
|
const KindQuasarCert zapv1.KindByte = 0x01
|
|
|
|
// SizeQuasarCert is the fixed object payload size in bytes.
|
|
const SizeQuasarCert = 72
|
|
|
|
// QuasarCertSchema is the v2 schema marker for QuasarCert. Methods are constant-
|
|
// returning so concrete-typed [zapv1.Wrap[QuasarCertSchema]] calls fold to
|
|
// literals at the call site.
|
|
type QuasarCertSchema struct{}
|
|
|
|
func (QuasarCertSchema) Kind() zapv1.KindByte { return KindQuasarCert }
|
|
func (QuasarCertSchema) Size() int { return SizeQuasarCert }
|
|
func (QuasarCertSchema) Name() string { return "QuasarCert" }
|
|
|
|
// OffsetQuasarCert_Epoch is the byte offset of the Epoch field.
|
|
const OffsetQuasarCert_Epoch = 8
|
|
|
|
// OffsetQuasarCert_FinalityUnixNano is the byte offset of the FinalityUnixNano field.
|
|
const OffsetQuasarCert_FinalityUnixNano = 16
|
|
|
|
// OffsetQuasarCert_Validators is the byte offset of the Validators field.
|
|
const OffsetQuasarCert_Validators = 24
|
|
|
|
// OffsetQuasarCert_BLSOff is the byte offset of the BLSOff field.
|
|
const OffsetQuasarCert_BLSOff = 32
|
|
|
|
// OffsetQuasarCert_BLSLen is the byte offset of the BLSLen field.
|
|
const OffsetQuasarCert_BLSLen = 36
|
|
|
|
// OffsetQuasarCert_CoronaOff is the byte offset of the CoronaOff field.
|
|
const OffsetQuasarCert_CoronaOff = 40
|
|
|
|
// OffsetQuasarCert_CoronaLen is the byte offset of the CoronaLen field.
|
|
const OffsetQuasarCert_CoronaLen = 44
|
|
|
|
// OffsetQuasarCert_PulsarOff is the byte offset of the PulsarOff field.
|
|
const OffsetQuasarCert_PulsarOff = 48
|
|
|
|
// OffsetQuasarCert_PulsarLen is the byte offset of the PulsarLen field.
|
|
const OffsetQuasarCert_PulsarLen = 52
|
|
|
|
// OffsetQuasarCert_MagnetarOff is the byte offset of the MagnetarOff field.
|
|
const OffsetQuasarCert_MagnetarOff = 56
|
|
|
|
// OffsetQuasarCert_MagnetarLen is the byte offset of the MagnetarLen field.
|
|
const OffsetQuasarCert_MagnetarLen = 60
|
|
|
|
// OffsetQuasarCert_MLDSARollupOff is the byte offset of the MLDSARollupOff field.
|
|
const OffsetQuasarCert_MLDSARollupOff = 64
|
|
|
|
// OffsetQuasarCert_MLDSARollupLen is the byte offset of the MLDSARollupLen field.
|
|
const OffsetQuasarCert_MLDSARollupLen = 68
|
|
|
|
// QuasarCertSchemaFields is the namespace of every scalar field accessor for QuasarCert.
|
|
// Use with [zapv1.Read] / [zapv1.Write] for type-safe access.
|
|
// Byte-array fields are emitted as standalone functions, see below.
|
|
var QuasarCertSchemaFields = struct {
|
|
Epoch zapv1.Field[QuasarCertSchema, uint64]
|
|
FinalityUnixNano zapv1.Field[QuasarCertSchema, int64]
|
|
Validators zapv1.Field[QuasarCertSchema, uint32]
|
|
BLSOff zapv1.Field[QuasarCertSchema, uint32]
|
|
BLSLen zapv1.Field[QuasarCertSchema, uint32]
|
|
CoronaOff zapv1.Field[QuasarCertSchema, uint32]
|
|
CoronaLen zapv1.Field[QuasarCertSchema, uint32]
|
|
PulsarOff zapv1.Field[QuasarCertSchema, uint32]
|
|
PulsarLen zapv1.Field[QuasarCertSchema, uint32]
|
|
MagnetarOff zapv1.Field[QuasarCertSchema, uint32]
|
|
MagnetarLen zapv1.Field[QuasarCertSchema, uint32]
|
|
MLDSARollupOff zapv1.Field[QuasarCertSchema, uint32]
|
|
MLDSARollupLen zapv1.Field[QuasarCertSchema, uint32]
|
|
}{
|
|
Epoch: zapv1.At[QuasarCertSchema, uint64](8),
|
|
FinalityUnixNano: zapv1.At[QuasarCertSchema, int64](16),
|
|
Validators: zapv1.At[QuasarCertSchema, uint32](24),
|
|
BLSOff: zapv1.At[QuasarCertSchema, uint32](32),
|
|
BLSLen: zapv1.At[QuasarCertSchema, uint32](36),
|
|
CoronaOff: zapv1.At[QuasarCertSchema, uint32](40),
|
|
CoronaLen: zapv1.At[QuasarCertSchema, uint32](44),
|
|
PulsarOff: zapv1.At[QuasarCertSchema, uint32](48),
|
|
PulsarLen: zapv1.At[QuasarCertSchema, uint32](52),
|
|
MagnetarOff: zapv1.At[QuasarCertSchema, uint32](56),
|
|
MagnetarLen: zapv1.At[QuasarCertSchema, uint32](60),
|
|
MLDSARollupOff: zapv1.At[QuasarCertSchema, uint32](64),
|
|
MLDSARollupLen: zapv1.At[QuasarCertSchema, uint32](68),
|
|
}
|
|
|
|
// NewQuasarCert builds a fresh QuasarCert in a ZAP buffer.
|
|
//
|
|
// Hand-rolled fast path: inlines v1 primitives ([zap.NewBuilder],
|
|
// [*Builder.StartObject], [*ObjectBuilder.Set*], [*Builder.Finish])
|
|
// so the entire build expands at the call site. Result: 1 heap
|
|
// alloc (the buffer), zero overhead vs v1.
|
|
func NewQuasarCert(epoch uint64, finalityUnixNano int64, validators uint32, bLSOff uint32, bLSLen uint32, coronaOff uint32, coronaLen uint32, pulsarOff uint32, pulsarLen uint32, magnetarOff uint32, magnetarLen uint32, mLDSARollupOff uint32, mLDSARollupLen uint32) (zapv1.View[QuasarCertSchema], []byte) {
|
|
b := zap.NewBuilder(zap.HeaderSize + SizeQuasarCert)
|
|
ob := b.StartObject(SizeQuasarCert)
|
|
ob.SetUint8(0, uint8(KindQuasarCert))
|
|
ob.SetUint64(OffsetQuasarCert_Epoch, epoch)
|
|
ob.SetInt64(OffsetQuasarCert_FinalityUnixNano, finalityUnixNano)
|
|
ob.SetUint32(OffsetQuasarCert_Validators, validators)
|
|
ob.SetUint32(OffsetQuasarCert_BLSOff, bLSOff)
|
|
ob.SetUint32(OffsetQuasarCert_BLSLen, bLSLen)
|
|
ob.SetUint32(OffsetQuasarCert_CoronaOff, coronaOff)
|
|
ob.SetUint32(OffsetQuasarCert_CoronaLen, coronaLen)
|
|
ob.SetUint32(OffsetQuasarCert_PulsarOff, pulsarOff)
|
|
ob.SetUint32(OffsetQuasarCert_PulsarLen, pulsarLen)
|
|
ob.SetUint32(OffsetQuasarCert_MagnetarOff, magnetarOff)
|
|
ob.SetUint32(OffsetQuasarCert_MagnetarLen, magnetarLen)
|
|
ob.SetUint32(OffsetQuasarCert_MLDSARollupOff, mLDSARollupOff)
|
|
ob.SetUint32(OffsetQuasarCert_MLDSARollupLen, mLDSARollupLen)
|
|
rootOff := ob.FinishAsRoot()
|
|
buf := b.Finish()
|
|
end := rootOff + SizeQuasarCert
|
|
return zapv1.AsView[QuasarCertSchema](zapv1.RawFromSlices(buf, rootOff, end)), buf
|
|
}
|
|
|
|
// WrapQuasarCert parses a ZAP buffer into a typed
|
|
// [zapv1.View[QuasarCert]]. Validates the wire frame and the kind
|
|
// discriminator at offset 0; returns [*zapv1.SchemaError] on kind
|
|
// mismatch.
|
|
//
|
|
// Hand-rolled fast path: inlines [zap.Parse] (which is itself
|
|
// inlineable). Zero heap allocs on the happy path; matches v1
|
|
// hand-rolled performance.
|
|
func WrapQuasarCert(b []byte) (zapv1.View[QuasarCertSchema], error) {
|
|
msg, err := zap.Parse(b)
|
|
if err != nil {
|
|
return zapv1.View[QuasarCertSchema]{}, err
|
|
}
|
|
root := msg.Root()
|
|
if got := root.Uint8(0); got != uint8(KindQuasarCert) {
|
|
return zapv1.View[QuasarCertSchema]{}, zapv1.NewSchemaError(
|
|
KindQuasarCert, zapv1.KindByte(got), "QuasarCert")
|
|
}
|
|
data := msg.Bytes()
|
|
rootOff := root.Offset()
|
|
end := rootOff + SizeQuasarCert
|
|
if end > len(data) {
|
|
end = len(data) // Read returns zero on OOB; v1 graceful degradation
|
|
}
|
|
return zapv1.AsView[QuasarCertSchema](zapv1.RawFromSlices(data, rootOff, end)), nil
|
|
}
|
|
|