schemas

package
v2.18.2+incompatible Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package schemas provides a container for Cap'n Proto reflection data. The code generated by capnpc-go will register its schema in the default registry (unless disabled at generation time).

Most programs will use the default registry. However, a program could dynamically build up a registry, perhaps by invoking the capnp tool or querying a service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find(id uint64) []byte

Find returns the CodeGeneratorRequest message for the given ID, suitable for capnp.Unmarshal, or nil if the ID was not found. It is safe to call Find from multiple goroutines, so the returned byte slice should not be modified. However, it is not safe to call Find concurrently with Register.

func IsNotFound

func IsNotFound(e error) bool

IsNotFound reports whether e indicates a failure to find a schema.

func Register

func Register(data string, ids ...uint64)

Register is called by generated code to associate a blob of zlib- compressed, packed Cap'n Proto data for a CodeGeneratorRequest with the IDs it contains. It should only be called during init().

Types

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

A Registry is a mapping of IDs to schema blobs. It is safe to read from multiple goroutines. The zero value is an empty registry.

var DefaultRegistry Registry

DefaultRegistry is the process-wide registry used by Register and Find.

func (*Registry) Find

func (reg *Registry) Find(id uint64) ([]byte, error)

Find returns the CodeGeneratorRequest message for the given ID, suitable for capnp.Unmarshal. If the ID is not found, Find returns an error that can be identified with IsNotFound. The returned byte slice should not be modified.

func (*Registry) Register

func (reg *Registry) Register(s *Schema) error

Register indexes a schema in the registry. It is an error to register schemas with overlapping IDs.

type Schema

type Schema struct {
	// Either String or Bytes must be populated with a CodeGeneratorRequest
	// message in the standard Cap'n Proto framing format.
	String string
	Bytes  []byte

	// If true, the input is assumed to be zlib-compressed and packed.
	Compressed bool

	// Node IDs that are contained in this schema.
	Nodes []uint64
}

A Schema is a collection of schema nodes parsed by the capnp tool.

Jump to

Keyboard shortcuts

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