Files
zap/v1/codegen/testpkg/lc_block_header_request_zap.go
zeekay af88152c6f rename v2 -> v1: the typed-view API + codegen is the canonical 1.0 (no v2, ever)
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.)
2026-06-23 15:05:15 -07:00

133 lines
6.1 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: LightClientBlockHeaderRequest (kind=0x50, size=51).
package lcwire
import (
"github.com/luxfi/zap"
zapv1 "github.com/luxfi/zap/v1"
)
// KindLightClientBlockHeaderRequest is the wire discriminator for LightClientBlockHeaderRequest.
const KindLightClientBlockHeaderRequest zapv1.KindByte = 0x50
// SizeLightClientBlockHeaderRequest is the fixed object payload size in bytes.
const SizeLightClientBlockHeaderRequest = 51
// LCBlockHeaderReqSchema is the v2 schema marker for LightClientBlockHeaderRequest. Methods are constant-
// returning so concrete-typed [zapv1.Wrap[LCBlockHeaderReqSchema]] calls fold to
// literals at the call site.
type LCBlockHeaderReqSchema struct{}
func (LCBlockHeaderReqSchema) Kind() zapv1.KindByte { return KindLightClientBlockHeaderRequest }
func (LCBlockHeaderReqSchema) Size() int { return SizeLightClientBlockHeaderRequest }
func (LCBlockHeaderReqSchema) Name() string { return "LightClientBlockHeaderRequest" }
// OffsetLightClientBlockHeaderRequest_Version is the byte offset of the Version field.
const OffsetLightClientBlockHeaderRequest_Version = 1
// OffsetLightClientBlockHeaderRequest_ChainID is the byte offset of the ChainID field.
const OffsetLightClientBlockHeaderRequest_ChainID = 2
// OffsetLightClientBlockHeaderRequest_BlockHeight is the byte offset of the BlockHeight field.
const OffsetLightClientBlockHeaderRequest_BlockHeight = 6
// OffsetLightClientBlockHeaderRequest_BlockContentHash is the byte offset of the BlockContentHash field.
const OffsetLightClientBlockHeaderRequest_BlockContentHash = 14
// OffsetLightClientBlockHeaderRequest_CertMinTier is the byte offset of the CertMinTier field.
const OffsetLightClientBlockHeaderRequest_CertMinTier = 46
// OffsetLightClientBlockHeaderRequest_RequestID is the byte offset of the RequestID field.
const OffsetLightClientBlockHeaderRequest_RequestID = 47
// LCBlockHeaderReqSchemaFields is the namespace of every scalar field accessor for LightClientBlockHeaderRequest.
// Use with [zapv1.Read] / [zapv1.Write] for type-safe access.
// Byte-array fields are emitted as standalone functions, see below.
var LCBlockHeaderReqSchemaFields = struct {
Version zapv1.Field[LCBlockHeaderReqSchema, uint8]
ChainID zapv1.Field[LCBlockHeaderReqSchema, uint32]
BlockHeight zapv1.Field[LCBlockHeaderReqSchema, uint64]
CertMinTier zapv1.Field[LCBlockHeaderReqSchema, uint8]
RequestID zapv1.Field[LCBlockHeaderReqSchema, uint32]
}{
Version: zapv1.At[LCBlockHeaderReqSchema, uint8](1),
ChainID: zapv1.At[LCBlockHeaderReqSchema, uint32](2),
BlockHeight: zapv1.At[LCBlockHeaderReqSchema, uint64](6),
CertMinTier: zapv1.At[LCBlockHeaderReqSchema, uint8](46),
RequestID: zapv1.At[LCBlockHeaderReqSchema, uint32](47),
}
// NewLightClientBlockHeaderRequest builds a fresh LightClientBlockHeaderRequest 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 NewLightClientBlockHeaderRequest(version uint8, chainID uint32, blockHeight uint64, certMinTier uint8, requestID uint32, blockContentHash [32]byte) (zapv1.View[LCBlockHeaderReqSchema], []byte) {
b := zap.NewBuilder(zap.HeaderSize + SizeLightClientBlockHeaderRequest)
ob := b.StartObject(SizeLightClientBlockHeaderRequest)
ob.SetUint8(0, uint8(KindLightClientBlockHeaderRequest))
ob.SetUint8(OffsetLightClientBlockHeaderRequest_Version, version)
ob.SetUint32(OffsetLightClientBlockHeaderRequest_ChainID, chainID)
ob.SetUint64(OffsetLightClientBlockHeaderRequest_BlockHeight, blockHeight)
ob.SetUint8(OffsetLightClientBlockHeaderRequest_CertMinTier, certMinTier)
ob.SetUint32(OffsetLightClientBlockHeaderRequest_RequestID, requestID)
ob.SetBytesFixed(OffsetLightClientBlockHeaderRequest_BlockContentHash, blockContentHash[:])
rootOff := ob.FinishAsRoot()
buf := b.Finish()
end := rootOff + SizeLightClientBlockHeaderRequest
return zapv1.AsView[LCBlockHeaderReqSchema](zapv1.RawFromSlices(buf, rootOff, end)), buf
}
// WrapLightClientBlockHeaderRequest parses a ZAP buffer into a typed
// [zapv1.View[LightClientBlockHeaderRequest]]. 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 WrapLightClientBlockHeaderRequest(b []byte) (zapv1.View[LCBlockHeaderReqSchema], error) {
msg, err := zap.Parse(b)
if err != nil {
return zapv1.View[LCBlockHeaderReqSchema]{}, err
}
root := msg.Root()
if got := root.Uint8(0); got != uint8(KindLightClientBlockHeaderRequest) {
return zapv1.View[LCBlockHeaderReqSchema]{}, zapv1.NewSchemaError(
KindLightClientBlockHeaderRequest, zapv1.KindByte(got), "LightClientBlockHeaderRequest")
}
data := msg.Bytes()
rootOff := root.Offset()
end := rootOff + SizeLightClientBlockHeaderRequest
if end > len(data) {
end = len(data) // Read returns zero on OOB; v1 graceful degradation
}
return zapv1.AsView[LCBlockHeaderReqSchema](zapv1.RawFromSlices(data, rootOff, end)), nil
}
// LightClientBlockHeaderRequestBlockContentHash reads the 32-byte inline BlockContentHash field of LightClientBlockHeaderRequest.
//
// Zero-copy on the read side (v1's Object.BytesFixedSlice returns
// a sub-slice of the underlying buffer); the returned [32]byte is a
// value copy so the caller's slot owns the bytes after the View's
// buffer is freed.
func LightClientBlockHeaderRequestBlockContentHash(v zapv1.View[LCBlockHeaderReqSchema]) [32]byte {
msg := zap.WrapBuffer(v.Bytes())
obj := msg.RootObjectAt(int(zapv1.RootOff(v)))
slice := obj.BytesFixedSlice(OffsetLightClientBlockHeaderRequest_BlockContentHash, 32)
var out [32]byte
if len(slice) == 32 {
copy(out[:], slice)
}
return out
}
func init() {
zapv1.Register[LCBlockHeaderReqSchema](zapv1.DefaultRegistry)
}