schema

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package schema reads a wire schema: a Go package of plain types marked with //wire: directives. It is what the generators in wire/gen consume.

//wire:message           on a struct: a top-level message (gets an id)
//wire:union             on an interface with one unexported method:
                         a value that is one of several structs
//wire:variant <Union>   on a struct: one of the union's variants
//wire:enum              on a named integer type: its constants are the values

Every other exported struct in the package is a plain nested type. The schema package must stand alone (no imports) so it can be type-checked without a build.

Index

Constants

View Source
const MessageUnion = "Message"

MessageUnion is the name of the generated union over every message.

Variables

This section is empty.

Functions

func Combine

func Combine(hashes []uint64) uint64

Combine is wire.Combine, the value hosts pass to nn_start.

Types

type EnumDef

type EnumDef struct {
	Name   string
	Doc    string
	Bits   int
	Signed bool
	Values []EnumValue
}

type EnumValue

type EnumValue struct {
	Name  string
	Value int64 // uint64 values are stored as their bit pattern
}

type Field

type Field struct {
	Name string // Go name, exported
	Type *Type
}

type Kind

type Kind int

Kind is a wire type's shape.

const (
	Bool Kind = iota
	Uint      // Bits: 8, 16, 32, 64
	Int       // Bits: 8, 16, 32, 64
	Float32
	Float64
	String
	Bytes
	List     // Elem
	Map      // Key, Elem
	Optional // Elem: a basic, string, enum or struct
	Struct   // Name
	Union    // Name; always nullable
	Enum     // Name; Bits and Signed from its base type
)

type Schema

type Schema struct {
	Package  string // Go package name, e.g. "proto"
	Dir      string
	Structs  []*StructDef
	Unions   []*UnionDef
	Enums    []*EnumDef
	Messages []string // message struct names; a message's id is its index + 1
	Hash     uint64   // FNV-1a of Canonical()
}

Schema is one package's wire types.

func Load

func Load(dir string) (*Schema, error)

Load reads the schema package in dir. Generated files (*_gen.go) and tests are ignored.

func (*Schema) Canonical

func (s *Schema) Canonical() string

Canonical is a stable text form of everything that affects the bytes on the wire; Hash is computed from it. Docs and Go spellings are left out.

type StructDef

type StructDef struct {
	Name    string
	Doc     string
	Fields  []Field
	Message bool // has //wire:message
}

type Type

type Type struct {
	Kind   Kind
	Bits   int
	Signed bool // for Enum
	Name   string
	Elem   *Type
	Key    *Type
	GoType string // the Go spelling, e.g. "[]*Child"
}

Type is a field's type.

type UnionDef

type UnionDef struct {
	Name     string
	Doc      string
	Marker   string   // the interface's one method, which variants get
	Variants []string // struct names, in declaration order
}

Jump to

Keyboard shortcuts

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