Files
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

148 lines
5.8 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: ZKVMUTXO (kind=0x03, size=72).
package zkvmwire
import (
"github.com/luxfi/zap"
zapv1 "github.com/luxfi/zap/v1"
)
// KindZKVMUTXO is the wire discriminator for ZKVMUTXO.
const KindZKVMUTXO zapv1.KindByte = 0x03
// SizeZKVMUTXO is the fixed object payload size in bytes.
const SizeZKVMUTXO = 72
// ZKVMUTXOSchema is the v2 schema marker for ZKVMUTXO. Methods are constant-
// returning so concrete-typed [zapv1.Wrap[ZKVMUTXOSchema]] calls fold to
// literals at the call site.
type ZKVMUTXOSchema struct{}
func (ZKVMUTXOSchema) Kind() zapv1.KindByte { return KindZKVMUTXO }
func (ZKVMUTXOSchema) Size() int { return SizeZKVMUTXO }
func (ZKVMUTXOSchema) Name() string { return "ZKVMUTXO" }
// OffsetZKVMUTXO_OutputIndex is the byte offset of the OutputIndex field.
const OffsetZKVMUTXO_OutputIndex = 4
// OffsetZKVMUTXO_Height is the byte offset of the Height field.
const OffsetZKVMUTXO_Height = 8
// OffsetZKVMUTXO_TxID is the byte offset of the TxID field.
const OffsetZKVMUTXO_TxID = 16
// OffsetZKVMUTXO_CommitmentOff is the byte offset of the CommitmentOff field.
const OffsetZKVMUTXO_CommitmentOff = 48
// OffsetZKVMUTXO_CommitmentLen is the byte offset of the CommitmentLen field.
const OffsetZKVMUTXO_CommitmentLen = 52
// OffsetZKVMUTXO_CiphertextOff is the byte offset of the CiphertextOff field.
const OffsetZKVMUTXO_CiphertextOff = 56
// OffsetZKVMUTXO_CiphertextLen is the byte offset of the CiphertextLen field.
const OffsetZKVMUTXO_CiphertextLen = 60
// OffsetZKVMUTXO_EphemeralPKOff is the byte offset of the EphemeralPKOff field.
const OffsetZKVMUTXO_EphemeralPKOff = 64
// OffsetZKVMUTXO_EphemeralPKLen is the byte offset of the EphemeralPKLen field.
const OffsetZKVMUTXO_EphemeralPKLen = 68
// ZKVMUTXOSchemaFields is the namespace of every scalar field accessor for ZKVMUTXO.
// Use with [zapv1.Read] / [zapv1.Write] for type-safe access.
// Byte-array fields are emitted as standalone functions, see below.
var ZKVMUTXOSchemaFields = struct {
OutputIndex zapv1.Field[ZKVMUTXOSchema, uint32]
Height zapv1.Field[ZKVMUTXOSchema, uint64]
CommitmentOff zapv1.Field[ZKVMUTXOSchema, uint32]
CommitmentLen zapv1.Field[ZKVMUTXOSchema, uint32]
CiphertextOff zapv1.Field[ZKVMUTXOSchema, uint32]
CiphertextLen zapv1.Field[ZKVMUTXOSchema, uint32]
EphemeralPKOff zapv1.Field[ZKVMUTXOSchema, uint32]
EphemeralPKLen zapv1.Field[ZKVMUTXOSchema, uint32]
}{
OutputIndex: zapv1.At[ZKVMUTXOSchema, uint32](4),
Height: zapv1.At[ZKVMUTXOSchema, uint64](8),
CommitmentOff: zapv1.At[ZKVMUTXOSchema, uint32](48),
CommitmentLen: zapv1.At[ZKVMUTXOSchema, uint32](52),
CiphertextOff: zapv1.At[ZKVMUTXOSchema, uint32](56),
CiphertextLen: zapv1.At[ZKVMUTXOSchema, uint32](60),
EphemeralPKOff: zapv1.At[ZKVMUTXOSchema, uint32](64),
EphemeralPKLen: zapv1.At[ZKVMUTXOSchema, uint32](68),
}
// NewZKVMUTXO builds a fresh ZKVMUTXO 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 NewZKVMUTXO(outputIndex uint32, height uint64, commitmentOff uint32, commitmentLen uint32, ciphertextOff uint32, ciphertextLen uint32, ephemeralPKOff uint32, ephemeralPKLen uint32, txID [32]byte) (zapv1.View[ZKVMUTXOSchema], []byte) {
b := zap.NewBuilder(zap.HeaderSize + SizeZKVMUTXO)
ob := b.StartObject(SizeZKVMUTXO)
ob.SetUint8(0, uint8(KindZKVMUTXO))
ob.SetUint32(OffsetZKVMUTXO_OutputIndex, outputIndex)
ob.SetUint64(OffsetZKVMUTXO_Height, height)
ob.SetUint32(OffsetZKVMUTXO_CommitmentOff, commitmentOff)
ob.SetUint32(OffsetZKVMUTXO_CommitmentLen, commitmentLen)
ob.SetUint32(OffsetZKVMUTXO_CiphertextOff, ciphertextOff)
ob.SetUint32(OffsetZKVMUTXO_CiphertextLen, ciphertextLen)
ob.SetUint32(OffsetZKVMUTXO_EphemeralPKOff, ephemeralPKOff)
ob.SetUint32(OffsetZKVMUTXO_EphemeralPKLen, ephemeralPKLen)
ob.SetBytesFixed(OffsetZKVMUTXO_TxID, txID[:])
rootOff := ob.FinishAsRoot()
buf := b.Finish()
end := rootOff + SizeZKVMUTXO
return zapv1.AsView[ZKVMUTXOSchema](zapv1.RawFromSlices(buf, rootOff, end)), buf
}
// WrapZKVMUTXO parses a ZAP buffer into a typed
// [zapv1.View[ZKVMUTXO]]. 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 WrapZKVMUTXO(b []byte) (zapv1.View[ZKVMUTXOSchema], error) {
msg, err := zap.Parse(b)
if err != nil {
return zapv1.View[ZKVMUTXOSchema]{}, err
}
root := msg.Root()
if got := root.Uint8(0); got != uint8(KindZKVMUTXO) {
return zapv1.View[ZKVMUTXOSchema]{}, zapv1.NewSchemaError(
KindZKVMUTXO, zapv1.KindByte(got), "ZKVMUTXO")
}
data := msg.Bytes()
rootOff := root.Offset()
end := rootOff + SizeZKVMUTXO
if end > len(data) {
end = len(data) // Read returns zero on OOB; v1 graceful degradation
}
return zapv1.AsView[ZKVMUTXOSchema](zapv1.RawFromSlices(data, rootOff, end)), nil
}
// ZKVMUTXOTxID reads the 32-byte inline TxID field of ZKVMUTXO.
//
// 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 ZKVMUTXOTxID(v zapv1.View[ZKVMUTXOSchema]) [32]byte {
msg := zap.WrapBuffer(v.Bytes())
obj := msg.RootObjectAt(int(zapv1.RootOff(v)))
slice := obj.BytesFixedSlice(OffsetZKVMUTXO_TxID, 32)
var out [32]byte
if len(slice) == 32 {
copy(out[:], slice)
}
return out
}