Files
zeekay 6439541c91 Prove the two backends agree, on bytes neither of them wrote
Generating C++ is a claim. This runs it.

Both probes build the same cases from the same inputs — every type the dialect
has, plus the request and response envelopes the generated client and dispatch
produce — and print the hex; the two outputs are the same file. Then each
probe reads both probes' bytes with its own generated accessors, four
crossings, all agreeing. Then both read a corpus of real P-chain transactions
produced by the Go chain implementation, 134 vectors of which 44 are truncated
or malformed on purpose, and answer the same fields in the same places.

Neither probe decides anything: every value printed comes from a generated
accessor or a generated builder, so a disagreement between the probes is a
disagreement between the backends and nowhere else.

It earned its keep immediately. Five corpus vectors separated a Go [N]byte
accessor answering zeros from a C++ span answering empty, and the round trip
found the zero Object panicking in the Go runtime where C++ answered zero.
Both are fixed; neither was visible by reading.

list<T> carries a pointer and a count and nothing about elements — the dialect
cannot state a stride — so both languages agree on the count, which is all
either can say. That gap is in the dialect, in both backends at once.
2026-09-06 08:35:14 -07:00

268 lines
7.6 KiB
Go

// Code generated by zapgen; DO NOT EDIT.
// source: echo.zap
package echo
import (
"fmt"
zap "github.com/zap-proto/go"
"github.com/zap-proto/go/rpc"
)
const (
pingSeqOff = 0
pingSize = 8
)
// Ping is a zero-copy view into a ZAP-encoded Ping message.
type Ping struct{ o zap.Object }
// WrapPing parses b and returns a typed view. Returns an error if the
// wire-level checks (magic, version, size) fail.
func WrapPing(b []byte) (Ping, error) {
m, err := zap.Parse(b)
if err != nil {
return Ping{}, err
}
return Ping{o: m.Root()}, nil
}
func (t Ping) Seq() uint64 { return t.o.Uint64(pingSeqOff) }
// PingInput collects the field values for NewPing.
type PingInput struct {
Seq uint64
}
// NewPing builds a ZAP-encoded Ping message from in and returns the bytes.
func NewPing(in PingInput) []byte {
b := zap.NewBuilder(256)
ob := b.StartObject(pingSize)
ob.SetUint64(pingSeqOff, in.Seq)
ob.FinishAsRoot()
return b.Finish()
}
const (
pongSeqOff = 0
pongSize = 8
)
// Pong is a zero-copy view into a ZAP-encoded Pong message.
type Pong struct{ o zap.Object }
// WrapPong parses b and returns a typed view. Returns an error if the
// wire-level checks (magic, version, size) fail.
func WrapPong(b []byte) (Pong, error) {
m, err := zap.Parse(b)
if err != nil {
return Pong{}, err
}
return Pong{o: m.Root()}, nil
}
func (t Pong) Seq() uint64 { return t.o.Uint64(pongSeqOff) }
// PongInput collects the field values for NewPong.
type PongInput struct {
Seq uint64
}
// NewPong builds a ZAP-encoded Pong message from in and returns the bytes.
func NewPong(in PongInput) []byte {
b := zap.NewBuilder(256)
ob := b.StartObject(pongSize)
ob.SetUint64(pongSeqOff, in.Seq)
ob.FinishAsRoot()
return b.Finish()
}
// Method ordinals for the Echo service (stable 1-based wire ids).
const (
EchoPingOrdinal uint32 = 1
EchoNotifyOrdinal uint32 = 2
EchoHealthOrdinal uint32 = 3
EchoShutdownOrdinal uint32 = 4
)
// EchoChannel ships one Call envelope and awaits its correlated Response.
type EchoChannel interface {
Call(envelope []byte) (rpc.Response, error)
}
// EchoClient is a typed RPC client for the Echo service over a ZAP call channel.
// Each call takes a fresh PromiseID from sess; the pipelined "On" form of a
// method sets Target to a prior call's Promise so the server chains them.
type EchoClient struct {
ch EchoChannel
cap []byte
sess *rpc.Session
}
// NewEchoClient returns a client that issues calls over ch, attaching cap
// (which may be nil) to every request.
func NewEchoClient(ch EchoChannel, capability []byte) *EchoClient {
return &EchoClient{ch: ch, cap: capability, sess: rpc.NewSession()}
}
func (c *EchoClient) Ping(req []byte) (rpc.Promise, []byte, error) {
return c.invokePing(rpc.NoTarget, req)
}
// PingOn issues Ping as a dependent call pipelined on the answer of on:
// the server substitutes on's resolved result for this call's payload
// before dispatch, so it ships without waiting for on to round-trip.
func (c *EchoClient) PingOn(on rpc.Promise) (rpc.Promise, []byte, error) {
return c.invokePing(on.ID, nil)
}
func (c *EchoClient) invokePing(target uint32, payload []byte) (rpc.Promise, []byte, error) {
p := c.sess.Next()
resp, err := c.ch.Call(rpc.BuildRequest(rpc.Call{
Method: EchoPingOrdinal,
PromiseID: p.ID,
Target: target,
Cap: c.cap,
Payload: payload,
}))
if err != nil {
return p, nil, err
}
if resp.Status != rpc.StatusOK {
return p, nil, fmt.Errorf("Echo.Ping: status %d", resp.Status)
}
return p, resp.Body, nil
}
func (c *EchoClient) Notify(req []byte) (rpc.Promise, error) {
return c.invokeNotify(rpc.NoTarget, req)
}
// NotifyOn issues Notify as a dependent call pipelined on the answer of on:
// the server substitutes on's resolved result for this call's payload
// before dispatch, so it ships without waiting for on to round-trip.
func (c *EchoClient) NotifyOn(on rpc.Promise) (rpc.Promise, error) {
return c.invokeNotify(on.ID, nil)
}
func (c *EchoClient) invokeNotify(target uint32, payload []byte) (rpc.Promise, error) {
p := c.sess.Next()
resp, err := c.ch.Call(rpc.BuildRequest(rpc.Call{
Method: EchoNotifyOrdinal,
PromiseID: p.ID,
Target: target,
Cap: c.cap,
Payload: payload,
}))
if err != nil {
return p, err
}
if resp.Status != rpc.StatusOK {
return p, fmt.Errorf("Echo.Notify: status %d", resp.Status)
}
return p, nil
}
func (c *EchoClient) Health() (rpc.Promise, []byte, error) {
return c.invokeHealth(rpc.NoTarget, nil)
}
// HealthOn issues Health as a dependent call pipelined on the answer of on:
// the server substitutes on's resolved result for this call's payload
// before dispatch, so it ships without waiting for on to round-trip.
func (c *EchoClient) HealthOn(on rpc.Promise) (rpc.Promise, []byte, error) {
return c.invokeHealth(on.ID, nil)
}
func (c *EchoClient) invokeHealth(target uint32, payload []byte) (rpc.Promise, []byte, error) {
p := c.sess.Next()
resp, err := c.ch.Call(rpc.BuildRequest(rpc.Call{
Method: EchoHealthOrdinal,
PromiseID: p.ID,
Target: target,
Cap: c.cap,
Payload: payload,
}))
if err != nil {
return p, nil, err
}
if resp.Status != rpc.StatusOK {
return p, nil, fmt.Errorf("Echo.Health: status %d", resp.Status)
}
return p, resp.Body, nil
}
func (c *EchoClient) Shutdown() (rpc.Promise, error) {
return c.invokeShutdown(rpc.NoTarget, nil)
}
// ShutdownOn issues Shutdown as a dependent call pipelined on the answer of on:
// the server substitutes on's resolved result for this call's payload
// before dispatch, so it ships without waiting for on to round-trip.
func (c *EchoClient) ShutdownOn(on rpc.Promise) (rpc.Promise, error) {
return c.invokeShutdown(on.ID, nil)
}
func (c *EchoClient) invokeShutdown(target uint32, payload []byte) (rpc.Promise, error) {
p := c.sess.Next()
resp, err := c.ch.Call(rpc.BuildRequest(rpc.Call{
Method: EchoShutdownOrdinal,
PromiseID: p.ID,
Target: target,
Cap: c.cap,
Payload: payload,
}))
if err != nil {
return p, err
}
if resp.Status != rpc.StatusOK {
return p, fmt.Errorf("Echo.Shutdown: status %d", resp.Status)
}
return p, nil
}
// EchoHandler is the server contract for the Echo service. Implement each
// method, then route requests to it with DispatchEcho.
type EchoHandler interface {
Ping(req []byte) ([]byte, error)
Notify(req []byte) error
Health() ([]byte, error)
Shutdown() error
}
// DispatchEcho decodes a Call envelope, routes it by method ordinal to h,
// and returns the response envelope. An unknown ordinal yields a
// StatusNotFound response; a handler error yields StatusInternal.
func DispatchEcho(h EchoHandler, envelope []byte) ([]byte, error) {
call, err := rpc.ParseRequest(envelope)
if err != nil {
return nil, err
}
switch call.Method {
case EchoPingOrdinal:
body, err := h.Ping(call.Payload)
if err != nil {
return rpc.BuildResponse(rpc.StatusInternal, call.PromiseID, nil), nil
}
return rpc.BuildResponse(rpc.StatusOK, call.PromiseID, body), nil
case EchoNotifyOrdinal:
if err := h.Notify(call.Payload); err != nil {
return rpc.BuildResponse(rpc.StatusInternal, call.PromiseID, nil), nil
}
return rpc.BuildResponse(rpc.StatusOK, call.PromiseID, nil), nil
case EchoHealthOrdinal:
body, err := h.Health()
if err != nil {
return rpc.BuildResponse(rpc.StatusInternal, call.PromiseID, nil), nil
}
return rpc.BuildResponse(rpc.StatusOK, call.PromiseID, body), nil
case EchoShutdownOrdinal:
if err := h.Shutdown(); err != nil {
return rpc.BuildResponse(rpc.StatusInternal, call.PromiseID, nil), nil
}
return rpc.BuildResponse(rpc.StatusOK, call.PromiseID, nil), nil
default:
return rpc.BuildResponse(rpc.StatusNotFound, call.PromiseID, nil), nil
}
}