prototype

package
v2.0.0-...-d24bc72 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2019 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package prototype provides builders to construct protobuf types that implement the interfaces defined in the protoreflect package.

Protobuf types can either be constructed as standalone types (e.g., StandaloneMessage), or together as a batch of types in a single proto file (e.g., File). When creating standalone types, additional information must be provided such as the full type name and the proto syntax. When creating an entire file, the syntax and full name is derived from the parent type.

Most types contain options, defined as messages in descriptor.proto. To avoid cyclic dependencies, the prototype package treats these options as opaque protoreflect.ProtoMessage values. In some cases where the option contains semantically important information (e.g., google.protobuf.MessageOptions.map_entry), this information must be provided as a field of the corresponding type (e.g., prototype.Message.MapEntry).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoEnum

GoEnum creates a new protoreflect.EnumType by combining the provided protoreflect.EnumDescriptor with the provided constructor function.

func GoExtension

GoExtension creates a new protoreflect.ExtensionType.

An enum type must be provided for enum extension fields if ExtensionDescriptor.EnumType does not implement protoreflect.EnumType, in which case it replaces the original enum in ExtensionDescriptor.

Similarly, a message type must be provided for message extension fields if ExtensionDescriptor.MessageType does not implement protoreflect.MessageType, in which case it replaces the original message in ExtensionDescriptor.

The Go type is currently determined automatically. The type is T for scalars and *[]T for lists (maps are not allowed). The type T is determined as follows:

+------------+-------------------------------------+
| Go type    | Protobuf kind                       |
+------------+-------------------------------------+
| bool       | BoolKind                            |
| int32      | Int32Kind, Sint32Kind, Sfixed32Kind |
| int64      | Int64Kind, Sint64Kind, Sfixed64Kind |
| uint32     | Uint32Kind, Fixed32Kind             |
| uint64     | Uint64Kind, Fixed64Kind             |
| float32    | FloatKind                           |
| float64    | DoubleKind                          |
| string     | StringKind                          |
| []byte     | BytesKind                           |
| E          | EnumKind                            |
| M          | MessageKind, GroupKind              |
+------------+-------------------------------------+

The type E is the concrete enum type returned by NewEnum, which is often, but not required to be, a named int32 type. The type M is the concrete message type returned by NewMessage, which is often, but not required to be, a pointer to a named struct type.

func GoMessage

GoMessage creates a new protoreflect.MessageType by combining the provided protoreflect.MessageDescriptor with the provided constructor function.

func NewEnum

NewEnum creates a new protoreflect.EnumDescriptor. The caller must relinquish full ownership of the input t and must not access or mutate any fields.

func NewExtension

NewExtension creates a new protoreflect.ExtensionDescriptor. The caller must relinquish full ownership of the input t and must not access or mutate any fields.

func NewFile

func NewFile(t *File) (protoreflect.FileDescriptor, error)

NewFile creates a new protoreflect.FileDescriptor from the provided value. The file must represent a valid proto file according to protobuf semantics.

Fields that reference an enum or message that is being declared within the same File can be represented using a placeholder descriptor. NewFile will automatically resolve the placeholder to point to a concrete descriptor. Alternatively, a reference descriptor obtained via Enum.Reference or Message.Reference can be used instead. The placeholder approach makes it possible to declare the file descriptor as a single File literal and is generally easier to use. The reference approach is more performant, but also more error prone.

The caller must relinquish full ownership of the input t and must not access or mutate any fields. The input must not contain slices that are sub-slices of each other.

func NewMessage

NewMessage creates a new protoreflect.MessageDescriptor. The caller must relinquish full ownership of the input t and must not access or mutate any fields.

func NewMessages

func NewMessages(ts []*StandaloneMessage) ([]protoreflect.MessageDescriptor, error)

NewMessages creates a set of new protoreflect.MessageDescriptors.

This constructor permits the creation of cyclic message types that depend on each other. For example, message A may have a field of type message B, where message B may have a field of type message A. In such a case, a placeholder message is used for these cyclic references.

The caller must relinquish full ownership of the input ts and must not access or mutate any fields.

func PlaceholderEnum

func PlaceholderEnum(name protoreflect.FullName) protoreflect.EnumDescriptor

PlaceholderEnum returns a placeholder protoreflect.EnumType where only the Name and FullName accessors are valid.

A placeholder can be used within File literals when referencing an enum that is declared within that file.

func PlaceholderFile

func PlaceholderFile(path string, pkg protoreflect.FullName) protoreflect.FileDescriptor

PlaceholderFile returns a placeholder protoreflect.FileType where only the Path and Package accessors are valid.

func PlaceholderMessage

func PlaceholderMessage(name protoreflect.FullName) protoreflect.MessageDescriptor

PlaceholderMessage returns a placeholder protoreflect.MessageType where only the Name and FullName accessors are valid.

A placeholder can be used within File literals when referencing a message that is declared within that file.

Types

type Enum

type Enum struct {
	Name           protoreflect.Name
	Values         []EnumValue
	ReservedNames  []protoreflect.Name
	ReservedRanges [][2]protoreflect.EnumNumber
	Options        protoreflect.ProtoMessage
	// contains filtered or unexported fields
}

Enum is a constructor for protoreflect.EnumDescriptor.

func (*Enum) Reference

func (e *Enum) Reference() protoreflect.EnumDescriptor

Reference returns e as a reference protoreflect.EnumDescriptor, which can be used to satisfy internal dependencies within a proto file. Methods on the returned descriptor are not valid until the file that this enum belongs to has been constructed via NewFile.

type EnumValue

type EnumValue struct {
	Name    protoreflect.Name
	Number  protoreflect.EnumNumber
	Options protoreflect.ProtoMessage
	// contains filtered or unexported fields
}

EnumValue is a constructor for protoreflect.EnumValueDescriptor.

type Extension

type Extension struct {
	Name         protoreflect.Name
	Number       protoreflect.FieldNumber
	Cardinality  protoreflect.Cardinality
	Kind         protoreflect.Kind
	Default      protoreflect.Value
	MessageType  protoreflect.MessageDescriptor
	EnumType     protoreflect.EnumDescriptor
	ExtendedType protoreflect.MessageDescriptor
	Options      protoreflect.ProtoMessage
	IsPacked     OptionalBool
	// contains filtered or unexported fields
}

Extension is a constructor for protoreflect.ExtensionDescriptor.

type Field

type Field struct {
	Name        protoreflect.Name
	Number      protoreflect.FieldNumber
	Cardinality protoreflect.Cardinality
	Kind        protoreflect.Kind
	JSONName    string
	Default     protoreflect.Value
	OneofName   protoreflect.Name
	MessageType protoreflect.MessageDescriptor
	EnumType    protoreflect.EnumDescriptor
	Options     protoreflect.ProtoMessage
	IsPacked    OptionalBool
	IsWeak      bool
	// contains filtered or unexported fields
}

Field is a constructor for protoreflect.FieldDescriptor.

type File

type File struct {
	Syntax  protoreflect.Syntax
	Path    string
	Package protoreflect.FullName
	Imports []protoreflect.FileImport
	Options protoreflect.ProtoMessage

	Enums      []Enum
	Messages   []Message
	Extensions []Extension
	Services   []Service
	// contains filtered or unexported fields
}

File is a constructor for protoreflect.FileDescriptor.

type Message

type Message struct {
	Name                  protoreflect.Name
	Fields                []Field
	Oneofs                []Oneof
	ReservedNames         []protoreflect.Name
	ReservedRanges        [][2]protoreflect.FieldNumber
	ExtensionRanges       [][2]protoreflect.FieldNumber
	ExtensionRangeOptions []protoreflect.ProtoMessage
	Options               protoreflect.ProtoMessage
	IsMapEntry            bool

	Enums      []Enum
	Messages   []Message
	Extensions []Extension
	// contains filtered or unexported fields
}

Message is a constructor for protoreflect.MessageDescriptor.

func (*Message) Reference

func (m *Message) Reference() protoreflect.MessageDescriptor

Reference returns m as a reference protoreflect.MessageDescriptor, which can be used to satisfy internal dependencies within a proto file. Methods on the returned descriptor are not valid until the file that this message belongs to has been constructed via NewFile.

type Method

type Method struct {
	Name              protoreflect.Name
	InputType         protoreflect.MessageDescriptor
	OutputType        protoreflect.MessageDescriptor
	IsStreamingClient bool
	IsStreamingServer bool
	Options           protoreflect.ProtoMessage
	// contains filtered or unexported fields
}

Method is a constructor for protoreflect.MethodDescriptor.

type Oneof

type Oneof struct {
	Name    protoreflect.Name
	Options protoreflect.ProtoMessage
	// contains filtered or unexported fields
}

Oneof is a constructor for protoreflect.OneofDescriptor.

type OptionalBool

type OptionalBool uint8

OptionalBool is a tristate boolean.

const (
	DefaultBool OptionalBool = iota
	True
	False
)

Tristate boolean values.

type Service

type Service struct {
	Name    protoreflect.Name
	Methods []Method
	Options protoreflect.ProtoMessage
	// contains filtered or unexported fields
}

Service is a constructor for protoreflect.ServiceDescriptor.

type StandaloneEnum

type StandaloneEnum struct {
	Syntax         protoreflect.Syntax
	FullName       protoreflect.FullName
	Values         []EnumValue
	ReservedNames  []protoreflect.Name
	ReservedRanges [][2]protoreflect.EnumNumber
	Options        protoreflect.ProtoMessage
	// contains filtered or unexported fields
}

StandaloneEnum is a constructor for a protoreflect.EnumDescriptor that does not have a parent.

type StandaloneExtension

type StandaloneExtension struct {
	FullName     protoreflect.FullName
	Number       protoreflect.FieldNumber
	Cardinality  protoreflect.Cardinality
	Kind         protoreflect.Kind
	Default      protoreflect.Value
	MessageType  protoreflect.MessageDescriptor
	EnumType     protoreflect.EnumDescriptor
	ExtendedType protoreflect.MessageDescriptor
	Options      protoreflect.ProtoMessage
	IsPacked     OptionalBool
	// contains filtered or unexported fields
}

StandaloneExtension is a constructor for a protoreflect.ExtensionDescriptor that does not have a parent.

type StandaloneMessage

type StandaloneMessage struct {
	Syntax                protoreflect.Syntax
	FullName              protoreflect.FullName
	Fields                []Field
	Oneofs                []Oneof
	ReservedNames         []protoreflect.Name
	ReservedRanges        [][2]protoreflect.FieldNumber
	ExtensionRanges       [][2]protoreflect.FieldNumber
	ExtensionRangeOptions []protoreflect.ProtoMessage
	Options               protoreflect.ProtoMessage
	IsMapEntry            bool
	// contains filtered or unexported fields
}

StandaloneMessage is a constructor for a protoreflect.MessageDescriptor that does not have a parent and has no child declarations.

Jump to

Keyboard shortcuts

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