grpcschema

package
v0.7.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package grpcschema holds a policy's gRPC schema as the engine reads messages with it (design 0013 §5, §6): the compiled form the operator puts in the bundle (bundlev1.GRPCSchema, which pkg/grpcschema/load reads), checked and indexed. The engine never parses descriptors: New checks integers and short strings only, so that a schema that passes can be walked without further checks.

Index

Constants

View Source
const (
	MaxMethods       = 4096
	MaxMessages      = 16384
	MaxFields        = 65536
	MaxMessageFields = 4096
	MaxFieldName     = 128
	MaxFullName      = 512
	MaxCompiledBytes = 1 << 20
)

Bounds of a compiled schema (design 0013 §5.4), which the operator's compiler and New both check.

Variables

This section is empty.

Functions

This section is empty.

Types

type Def

type Def struct {
	ID, Source string
	// Size is the compiled size in bytes.
	Size     int
	Methods  []MethodDef
	Messages []MessageDef
}

Def is a compiled schema as plain data (bundlev1.GRPCSchema, which pkg/grpcschema/load reads): what New checks and indexes. The package doesn't import the bundle, so that the reader (pkg/grpcwire) links no protobuf runtime.

type Field

type Field struct {
	Number protowire.Number
	// Name is the proto name, or "[package.extension]".
	Name string
	Kind Kind
	// Message is the type of a KindMessage or KindGroup field.
	Message *Message
	// Repeated: a repeated number may come packed.
	Repeated bool
	// contains filtered or unexported fields
}

Field is a field of a message type.

func (*Field) Path

func (f *Field) Path(prefix string) string

Path returns the field's path under prefix, the path of its message: prefix + "." + Name, or Name at the top. The last one built is kept, so that a field read under the same prefix again, as the fields of repeated messages are, costs nothing.

type FieldDef

type FieldDef struct {
	Number   uint32
	Name     string
	Kind     Kind
	Message  uint32
	Repeated bool
}

FieldDef is a field: Message, for KindMessage and KindGroup only, is an index into Def.Messages.

type Kind

type Kind uint8

Kind is how a field's value is read: the values of bundlev1.GRPCFieldKind.

const (
	KindString Kind = iota + 1
	KindBytes
	KindMessage
	KindGroup
	KindVarint
	KindFixed32
	KindFixed64
)

The kinds of bundlev1.GRPCFieldKind.

type Message

type Message struct {
	FullName string
	// Any: google.protobuf.Any, whose value is read as the type its
	// type_url names.
	Any bool
	// contains filtered or unexported fields
}

Message is a message type.

func (*Message) Field

func (t *Message) Field(num protowire.Number) *Field

Field returns the field numbered num, or nil when t has none.

func (*Message) FieldAt

func (t *Message) FieldAt(i int) *Field

FieldAt returns t's i-th field, by number.

func (*Message) Fields

func (t *Message) Fields() int

Fields returns how many fields t has.

type MessageDef

type MessageDef struct {
	FullName string
	Any      bool
	Fields   []FieldDef
}

MessageDef is a message type.

type MethodDef

type MethodDef struct {
	Path          string
	Input, Output uint32
}

MethodDef is a method: its path, and its input and output types, indexes into Def.Messages.

type Schema

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

Schema is a loaded schema. It is immutable and safe for concurrent use.

func New

func New(d Def) (*Schema, error)

New checks a compiled schema and indexes it. An error means the schema can't be read with: the operator compiles only schemas that pass, so the bundle carrying it is invalid.

func (*Schema) AnyType

func (s *Schema) AnyType(typeURL string) *Message

AnyType returns the message type an Any's type_url names: the part after its last '/' ("type.googleapis.com/package.Message"), or nil.

func (*Schema) ID

func (s *Schema) ID() string

ID is the schema's id, the hash the bundle names it by.

func (*Schema) Message

func (s *Schema) Message(fullName string) *Message

Message returns the message type of a full name ("package.Message"), for an Any's type_url, or nil when the schema doesn't have it.

func (*Schema) Method

func (s *Schema) Method(path string) *Message

Method returns the input type of the method a call's path names ("/package.Service/Method", without a query), or nil when the schema doesn't describe it. s may be nil: no schema describes nothing.

func (*Schema) Methods

func (s *Schema) Methods() int

Methods is how many methods it describes.

func (*Schema) Size

func (s *Schema) Size() int

Size is its compiled size in bytes.

func (*Schema) Source

func (s *Schema) Source() string

Source is where its descriptor set came from: "namespace/configmap/key".

Directories

Path Synopsis
Package compile compiles a FileDescriptorSet into the schema engines read gRPC messages with (design 0013 §5.1, §5.2): the operator runs it on a policy's descriptor set, so that engines never parse descriptors.
Package compile compiles a FileDescriptorSet into the schema engines read gRPC messages with (design 0013 §5.1, §5.2): the operator runs it on a policy's descriptor set, so that engines never parse descriptors.
Package grpcschematest builds gRPC schemas for tests, as the operator compiles them and an engine loads them.
Package grpcschematest builds gRPC schemas for tests, as the operator compiles them and an engine loads them.
Package load reads a bundle's compiled gRPC schema (bundlev1.GRPCSchema) into a grpcschema.Schema.
Package load reads a bundle's compiled gRPC schema (bundlev1.GRPCSchema) into a grpcschema.Schema.

Jump to

Keyboard shortcuts

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