protobuf

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package protobuf contains structures to represent a protobuf definition, and tools to create textual representation of the definition.

Index

Constants

This section is empty.

Variables

View Source
var (
	BoolType   = newBuiltin("bool")
	BytesType  = newBuiltin("bytes")
	DoubleType = newBuiltin("double")
	FloatType  = newBuiltin("float")
	Int32Type  = newBuiltin("int32")
	Int64Type  = newBuiltin("int64")
	StringType = newBuiltin("string")
)

Builtin types

View Source
var (
	AnyType         = NewMessage("google.protobuf.Any")
	BoolValueType   = NewMessage("google.protobuf.BoolValue")
	BytesValueType  = NewMessage("google.protobuf.BytesValue")
	DoubleValueType = NewMessage("google.protobuf.DoubleValue")
	FloatValueType  = NewMessage("google.protobuf.FloatValue")
	Int32ValueType  = NewMessage("google.protobuf.Int32Value")
	Int64ValueType  = NewMessage("google.protobuf.Int64Value")
	NullValueType   = NewMessage("google.protobuf.NullValue")
	StringValueType = NewMessage("google.protobuf.StringValue")
)

Boxed types

View Source
var (
	ListValueType = NewMessage("google.protobuf.ListValue")
)

list type

View Source
var (
	StructType = NewMessage("google.protobuf.Struct")
)

value type

Functions

This section is empty.

Types

type Builtin

type Builtin string

Builtin represents a Protocol Buffers builting type

func (Builtin) Name

func (b Builtin) Name() string

Name returns the name of this type

func (Builtin) Priority

func (b Builtin) Priority() int

Priority returns the priority number for this type (note: Builtin does not get listed under the Protocol Buffers definition)

type Container

type Container interface {
	Type
	AddType(Type)
	Children() []Type
}

Container is a special type that can have child types

type Encoder

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

Encoder is responsible for taking a protobuf.Package object and encodes it into textual representation

func NewEncoder

func NewEncoder(dst io.Writer, options ...Option) *Encoder

NewEncoder creates an Encoder object that writes the encoded Protocol Buffers declaration to `dst`

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) error

Encode takes a protobuf.Package and encodes it to the destination

func (*Encoder) EncodeEnum

func (e *Encoder) EncodeEnum(v *Enum) error

EncodeEnum encodes an Enum object

func (*Encoder) EncodeExtension

func (e *Encoder) EncodeExtension(ext *Extension) error

EncodeExtension encodes an Extension object

func (*Encoder) EncodeExtensionField

func (e *Encoder) EncodeExtensionField(f *ExtensionField) error

EncodeExtensionField encodes an ExtensionField object

func (*Encoder) EncodeField

func (e *Encoder) EncodeField(v *Field) error

EncodeField encods the message field

func (*Encoder) EncodeGlobalOption

func (e *Encoder) EncodeGlobalOption(o *GlobalOption) error

EncodeGlobalOption encodes a GlobationOption object

func (*Encoder) EncodeHTTPAnnotation

func (e *Encoder) EncodeHTTPAnnotation(a *HTTPAnnotation) error

EncodeHTTPAnnotation encods a HTTPAnnotation object

func (*Encoder) EncodeMessage

func (e *Encoder) EncodeMessage(v *Message) error

EncodeMessage encodes a Message object

func (*Encoder) EncodePackage

func (e *Encoder) EncodePackage(p *Package) error

EncodePackage encodes a Package

func (*Encoder) EncodeRPC

func (e *Encoder) EncodeRPC(r *RPC) error

EncodeRPC encodes an RPC object

func (*Encoder) EncodeRPCOption

func (e *Encoder) EncodeRPCOption(v interface{}) error

EncodeRPCOption encodes RPC options

func (*Encoder) EncodeService

func (e *Encoder) EncodeService(s *Service) error

EncodeService encodes a Service object

func (*Encoder) EncodeType

func (e *Encoder) EncodeType(v Type) error

EncodeType detected Package, Enum, Message, Service, and Extension types and encodes them

type Enum

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

Enum represents a Protocol Buffers enum type

func NewEnum

func NewEnum(name string) *Enum

NewEnum creates an Enum object

func (*Enum) AddElement

func (e *Enum) AddElement(n interface{})

AddElement adds a new enum element

func (*Enum) Name

func (e *Enum) Name() string

Name returns the name of this type

func (*Enum) Priority

func (e *Enum) Priority() int

Priority returns the priority number for this type

func (*Enum) SetComment

func (e *Enum) SetComment(s string)

SetComment sets the comment associated with this enum

type Extension

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

Extension represents an extended message

func NewExtension

func NewExtension(base string) *Extension

NewExtension creates an Extension object

func (*Extension) AddField

func (e *Extension) AddField(f *ExtensionField)

AddField adds an ExtensionField

func (*Extension) Name

func (e *Extension) Name() string

Name returns the name of this type

func (*Extension) Priority

func (e *Extension) Priority() int

Priority returns the priority number for this type

type ExtensionField

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

ExtensionField is a field in an extended field

func NewExtensionField

func NewExtensionField(name, typ string, number int) *ExtensionField

NewExtensionField creates an ExtensionField object

type Field

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

Field is a field in a Message

func NewField

func NewField(typ Type, name string, index int) *Field

NewField creates a new Field object

func (*Field) Index

func (f *Field) Index() int

Index returns the number associated to this field

func (*Field) Name

func (f *Field) Name() string

Name returns the name of this type

func (*Field) SetComment

func (f *Field) SetComment(s string)

SetComment sets the comment associated to this field

func (*Field) SetRepeated

func (f *Field) SetRepeated(b bool)

SetRepeated sets if this field can be repeated

func (*Field) Type

func (f *Field) Type() Type

Type returns the Type of this field

type GlobalOption

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

GlobalOption represents a Protocol Buffers global option

func NewGlobalOption

func NewGlobalOption(name, value string) *GlobalOption

NewGlobalOption creates a GlobalOption

func (*GlobalOption) Name

func (o *GlobalOption) Name() string

Name returns the name of the GlobalOption

func (*GlobalOption) Value

func (o *GlobalOption) Value() string

Value returns the value of the GlobalOption

type HTTPAnnotation

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

HTTPAnnotation represents a google.api.http option

func NewHTTPAnnotation

func NewHTTPAnnotation(method, path string) *HTTPAnnotation

NewHTTPAnnotation creates an HTTPAnnotation object

func (*HTTPAnnotation) SetBody

func (a *HTTPAnnotation) SetBody(s string)

SetBody sets the body optional parameter

type Map

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

Map represents a Protocol Buffers map type

func NewMap

func NewMap(key, value Type) *Map

NewMap creates a map type

func (*Map) Name

func (m *Map) Name() string

Name returns the name of this type

func (*Map) Priority

func (m *Map) Priority() int

Priority returns the priority number for this type (note: Map does not get listed under the Protocol Buffers definition)

type Message

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

Message is a composite type

func NewMessage

func NewMessage(name string) *Message

NewMessage creates a new Message

func (*Message) AddField

func (m *Message) AddField(f *Field)

AddField adds Field objects to this message

func (*Message) AddType

func (m *Message) AddType(t Type)

AddType adds a child type

func (*Message) Children

func (m *Message) Children() []Type

Children returns the associated child types

func (*Message) Name

func (m *Message) Name() string

Name returns the name of this type

func (*Message) Priority

func (m *Message) Priority() int

Priority returns the priority number for this type

func (*Message) SetComment

func (m *Message) SetComment(s string)

SetComment sets the comment associated to this message

type Option

type Option = option.Option

Option is used to pass options to several methods

func WithIndent

func WithIndent(s string) Option

WithIndent creates a new Option to control the indentation for the encoded definition

type Package

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

Package represnets a Protocol Buffers Package.

func NewPackage

func NewPackage(name string) *Package

NewPackage creates a Package object

func (*Package) AddImport

func (p *Package) AddImport(s string)

AddImport adds a package to import

func (*Package) AddOption

func (p *Package) AddOption(t *GlobalOption)

AddOption adds a global option

func (*Package) AddType

func (p *Package) AddType(t Type)

AddType adds a child type

func (*Package) Children

func (p *Package) Children() []Type

Children returns the child types associated with this type

func (*Package) Name

func (p *Package) Name() string

Name returns the name of this type

func (*Package) Priority

func (p *Package) Priority() int

Priority returns the priority number for this type

type RPC

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

RPC represents an RPC call associated with a Service

func NewRPC

func NewRPC(name string) *RPC

NewRPC creates a new RPC object

func (*RPC) AddOption

func (r *RPC) AddOption(v interface{})

AddOption adds rpc options to the RPC

func (*RPC) Comment

func (r *RPC) Comment() string

Comment returns the comment string associated with the RPC

func (*RPC) Name

func (r *RPC) Name() string

Name returns the name of this rpc call

func (*RPC) Parameter

func (r *RPC) Parameter() Type

Parameter returns the type of parameter message

func (*RPC) Response

func (r *RPC) Response() Type

Response returns the type of response message

func (*RPC) SetComment

func (r *RPC) SetComment(s string)

SetComment sets the comment

func (*RPC) SetParameter

func (r *RPC) SetParameter(m *Message)

SetParameter sets the parameter type

func (*RPC) SetResponse

func (r *RPC) SetResponse(m *Message)

SetResponse sets the response type

type RPCOption

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

RPCOption represents simple rpc options

func NewRPCOption

func NewRPCOption(name string, value interface{}) *RPCOption

NewRPCOption create an RPCOption object

type Reference

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

Reference is a special type of Type that can pass the protobuf.Type system, but requires that it be resolved at runtime to get the actual Type behind it. This is used to resolve circular dependencies that are found during compilation phase

func NewReference

func NewReference(name string) *Reference

NewReference creates

func (*Reference) Name

func (r *Reference) Name() string

Name returns the reference string

func (*Reference) Priority

func (r *Reference) Priority() int

Priority returns the priority number for this type (note: Reference does not get listed under the Protocol Buffers definition)

type ResolveFunc

type ResolveFunc func(string) (Type, error)

ResolveFunc is the function used to resolve `$ref` strings to an actual protobuf.Type

type Service

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

Service defines a service with many RPC endpoints

func NewService

func NewService(name string) *Service

NewService creates a Service object

func (*Service) AddRPC

func (s *Service) AddRPC(r *RPC)

AddRPC associates an RPC object to this service

func (*Service) Name

func (s *Service) Name() string

Name returns the name of this type

func (*Service) Priority

func (s *Service) Priority() int

Priority returns the priority number for this type

type Type

type Type interface {
	Name() string
	Priority() int
}

Type is an interface to group different Protocol Buffer types

func Resolve

func Resolve(p *Package, resolver ResolveFunc) (Type, error)

Resolve takes a package, and resolves internal references. Note that you must have external references already resolved.

Jump to

Keyboard shortcuts

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