Files
zeekay 2210675e6e The info, admin and health replies cross the plane carrying their values
A ZAP field is an offset. Eight of these replies held a map, which has no
order to give one, so the reply could not cross between two processes at
all. Two more held values whose fields are every one unexported —
netip.AddrPort, time.Time — and those are worse: they are not refused, they
derive an EMPTY layout, so the reply crossed, reported no error and carried
nothing. GetNodeIPReply has one field, so its whole answer was blank. And a
health check says what it likes, so its details were an `any`, which has no
shape until it holds something.

Each map is now a list of a stated element type, ordered by the key it was
an object of. An address is the text netip already wrote for it, an instant
is three numbers, and a check details are the bytes of their own JSON —
the one shape an object, a string and a list all share.

The JSON does not move. Every list marshals to the object it replaced and
reads one back, and wire_test.go holds that against the old shape spelled
out as a literal rather than against itself. The order is new where there
was none: a map answered the same question two ways.

APIReply also states the status it carries, so the 503 a probe reads and
the healthy a person reads are one fact computed once.
2026-08-29 22:53:03 -07:00

264 lines
6.1 KiB
Go

// Code generated by zip; DO NOT EDIT.
package health
import (
"encoding/binary"
"fmt"
"strings"
"time"
types "github.com/luxfi/api/types"
zap "github.com/zap-proto/go"
)
// ---- APIArgs -----------------------------------------------------------
const (
aPIArgsTagsAt = 0
aPIArgsSize = 8
)
var _ interface {
MarshalZAP() ([]byte, error)
UnmarshalZAP([]byte) error
} = (*APIArgs)(nil)
// MarshalZAP writes APIArgs from constant offsets.
func (x *APIArgs) MarshalZAP() ([]byte, error) {
if x == nil {
return nil, nil
}
b := zap.NewBuilder(aPIArgsSize + 256)
tagsAt, tagsN := 0, len(x.Tags)
if tagsN > 0 {
var blob []byte
for i := range x.Tags {
enc := []byte(x.Tags[i])
var n [4]byte
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
blob = append(blob, n[:]...)
blob = append(blob, enc...)
}
tagsAt = b.WriteBytes(blob)
}
ob := b.StartObject(aPIArgsSize)
if tagsN > 0 {
ob.SetList(aPIArgsTagsAt, tagsAt, tagsN)
}
ob.FinishAsRoot()
return b.Finish(), nil
}
// UnmarshalZAP reads APIArgs out of the buffer that arrived.
func (x *APIArgs) UnmarshalZAP(data []byte) error {
if x == nil || len(data) == 0 {
return nil
}
m, err := zap.Parse(data)
if err != nil {
return fmt.Errorf("APIArgs: %w", err)
}
o := m.Root()
if l := o.List(aPIArgsTagsAt); l.Len() > 0 {
rows := make([]string, l.Len())
for i := range rows {
rows[i] = string(l.BytesAt(i))
}
x.Tags = rows
}
return nil
}
// ---- APIReply ----------------------------------------------------------
const (
aPIReplyChecksAt = 0
aPIReplyHealthyAt = 8
aPIReplySize = 16
)
var _ interface {
MarshalZAP() ([]byte, error)
UnmarshalZAP([]byte) error
} = (*APIReply)(nil)
// MarshalZAP writes APIReply from constant offsets.
func (x *APIReply) MarshalZAP() ([]byte, error) {
if x == nil {
return nil, nil
}
b := zap.NewBuilder(aPIReplySize + 256)
checksAt, checksN := 0, len(x.Checks)
if checksN > 0 {
var blob []byte
for i := range x.Checks {
enc, err := x.Checks[i].MarshalZAP()
if err != nil {
return nil, err
}
var n [4]byte
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
blob = append(blob, n[:]...)
blob = append(blob, enc...)
}
checksAt = b.WriteBytes(blob)
}
ob := b.StartObject(aPIReplySize)
ob.SetBool(aPIReplyHealthyAt, bool(x.Healthy))
if checksN > 0 {
ob.SetList(aPIReplyChecksAt, checksAt, checksN)
}
ob.FinishAsRoot()
return b.Finish(), nil
}
// UnmarshalZAP reads APIReply out of the buffer that arrived.
func (x *APIReply) UnmarshalZAP(data []byte) error {
if x == nil || len(data) == 0 {
return nil
}
m, err := zap.Parse(data)
if err != nil {
return fmt.Errorf("APIReply: %w", err)
}
o := m.Root()
if l := o.List(aPIReplyChecksAt); l.Len() > 0 {
rows := make(Checks, l.Len())
for i := range rows {
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
return err
}
}
x.Checks = rows
}
x.Healthy = bool(o.Bool(aPIReplyHealthyAt))
return nil
}
// ---- Check -------------------------------------------------------------
const (
checkNameAt = 0
checkResultAt = 8
checkSize = 16
)
var _ interface {
MarshalZAP() ([]byte, error)
UnmarshalZAP([]byte) error
} = (*Check)(nil)
// MarshalZAP writes Check from constant offsets.
func (x *Check) MarshalZAP() ([]byte, error) {
if x == nil {
return nil, nil
}
b := zap.NewBuilder(checkSize + 256)
ob := b.StartObject(checkSize)
ob.SetText(checkNameAt, string(x.Name))
innerResult, err := x.Result.MarshalZAP()
if err != nil {
return nil, err
}
ob.SetBytes(checkResultAt, innerResult)
ob.FinishAsRoot()
return b.Finish(), nil
}
// UnmarshalZAP reads Check out of the buffer that arrived.
func (x *Check) UnmarshalZAP(data []byte) error {
if x == nil || len(data) == 0 {
return nil
}
m, err := zap.Parse(data)
if err != nil {
return fmt.Errorf("Check: %w", err)
}
o := m.Root()
x.Name = string(strings.Clone(o.Text(checkNameAt)))
if raw := o.Bytes(checkResultAt); len(raw) > 0 {
if err := x.Result.UnmarshalZAP(raw); err != nil {
return err
}
}
return nil
}
// ---- Result ------------------------------------------------------------
const (
resultDetailsAt = 0
resultErrorAt = 8
resultTimestampAt = 16
resultDurationAt = 24
resultContiguousFailuresAt = 32
resultTimeOfFirstFailureAt = 40
resultSize = 48
)
var _ interface {
MarshalZAP() ([]byte, error)
UnmarshalZAP([]byte) error
} = (*Result)(nil)
// MarshalZAP writes Result from constant offsets.
func (x *Result) MarshalZAP() ([]byte, error) {
if x == nil {
return nil, nil
}
b := zap.NewBuilder(resultSize + 256)
ob := b.StartObject(resultSize)
ob.SetBytes(resultDetailsAt, []byte(x.Details))
if x.Error != nil {
ob.SetText(resultErrorAt, string((*x.Error)))
}
innerTimestamp, err := x.Timestamp.MarshalZAP()
if err != nil {
return nil, err
}
ob.SetBytes(resultTimestampAt, innerTimestamp)
ob.SetInt64(resultDurationAt, int64(x.Duration))
ob.SetInt64(resultContiguousFailuresAt, int64(x.ContiguousFailures))
if x.TimeOfFirstFailure != nil {
innerTimeOfFirstFailure, err := x.TimeOfFirstFailure.MarshalZAP()
if err != nil {
return nil, err
}
ob.SetBytes(resultTimeOfFirstFailureAt, innerTimeOfFirstFailure)
}
ob.FinishAsRoot()
return b.Finish(), nil
}
// UnmarshalZAP reads Result out of the buffer that arrived.
func (x *Result) UnmarshalZAP(data []byte) error {
if x == nil || len(data) == 0 {
return nil
}
m, err := zap.Parse(data)
if err != nil {
return fmt.Errorf("Result: %w", err)
}
o := m.Root()
x.Details = types.Raw(append([]byte(nil), o.Bytes(resultDetailsAt)...))
if v := string(strings.Clone(o.Text(resultErrorAt))); v != "" {
x.Error = &v
}
if raw := o.Bytes(resultTimestampAt); len(raw) > 0 {
if err := x.Timestamp.UnmarshalZAP(raw); err != nil {
return err
}
}
x.Duration = time.Duration(o.Int64(resultDurationAt))
x.ContiguousFailures = int64(o.Int64(resultContiguousFailuresAt))
if raw := o.Bytes(resultTimeOfFirstFailureAt); len(raw) > 0 {
var v types.Time
if err := v.UnmarshalZAP(raw); err != nil {
return err
}
x.TimeOfFirstFailure = &v
}
return nil
}