schema

package
v1.4.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package schema reads a .zap schema file.

The generator (zap-proto/go cmd/zapgen) has a parser, but it lives in a main package and cannot be imported, so a schema shipped next to a codec is prose that nothing checks. This reader closes that: a test can load the .zap and hold the shipped codec to it.

Grammar, as zapgen defines it:

file   := 'package' ident (alias | struct | interface)*
alias  := 'type' ident '=' type
struct := 'struct' ident '{' field* '}'
field  := ident type '@' int
type   := 'list' '<' type '>' | 'bytes_fixed' '[' int ']'
        | bool | u8 | u16 | u32 | u64 | i8 | i16 | i32 | i64
        | f32 | f64 | bytes | text | ident

'#' runs to end of line. Interfaces are skipped: they declare calls, and this reader is about layout.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Name  string
	Kind  Kind
	Fixed int  // bytes_fixed[N]
	Elem  Kind // list<T>
	Off   int
}

Field is one declared field.

type File

type File struct {
	Package string
	Structs []*Struct
}

File is a parsed schema.

func Parse

func Parse(src []byte) (*File, error)

Parse reads a .zap source file.

func (*File) Struct

func (f *File) Struct(name string) (*Struct, bool)

Struct returns the named struct, or false.

type Kind

type Kind string

Kind is a field's declared type, spelled as the schema spells it.

func (Kind) Width

func (k Kind) Width(fixed int) int

Width is the field's byte width in the fixed section, matching zapgen: scalars inline, bytes/text/list an {offset,length} pair, bytes_fixed[N] N bytes inline, a nested struct a single offset.

type Struct

type Struct struct {
	Name   string
	Fields []Field
}

Struct is one declared struct. Size is max(off+width), which is what zapgen emits as the object's fixed-section size.

func (*Struct) Field

func (s *Struct) Field(name string) (Field, bool)

Field returns the named field, or false.

func (*Struct) Size

func (s *Struct) Size() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL