pb

package
v0.0.0-...-bd88044 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package pb reflects over protocol buffer descriptors to generate objects that simplify type, enum, and field lookup.

Index

Constants

This section is empty.

Variables

View Source
var (
	// CheckedPrimitives map from proto field descriptor type to expr.Type.
	CheckedPrimitives = map[descpb.FieldDescriptorProto_Type]*exprpb.Type{
		descpb.FieldDescriptorProto_TYPE_BOOL:    checkedBool,
		descpb.FieldDescriptorProto_TYPE_BYTES:   checkedBytes,
		descpb.FieldDescriptorProto_TYPE_DOUBLE:  checkedDouble,
		descpb.FieldDescriptorProto_TYPE_FLOAT:   checkedDouble,
		descpb.FieldDescriptorProto_TYPE_INT32:   checkedInt,
		descpb.FieldDescriptorProto_TYPE_INT64:   checkedInt,
		descpb.FieldDescriptorProto_TYPE_SINT32:  checkedInt,
		descpb.FieldDescriptorProto_TYPE_SINT64:  checkedInt,
		descpb.FieldDescriptorProto_TYPE_UINT32:  checkedUint,
		descpb.FieldDescriptorProto_TYPE_UINT64:  checkedUint,
		descpb.FieldDescriptorProto_TYPE_FIXED32: checkedUint,
		descpb.FieldDescriptorProto_TYPE_FIXED64: checkedUint,
		descpb.FieldDescriptorProto_TYPE_STRING:  checkedString}

	// CheckedWellKnowns map from qualified proto type name to expr.Type for
	// well-known proto types.
	CheckedWellKnowns = map[string]*exprpb.Type{

		"google.protobuf.BoolValue":   checkedWrap(checkedBool),
		"google.protobuf.BytesValue":  checkedWrap(checkedBytes),
		"google.protobuf.DoubleValue": checkedWrap(checkedDouble),
		"google.protobuf.FloatValue":  checkedWrap(checkedDouble),
		"google.protobuf.Int64Value":  checkedWrap(checkedInt),
		"google.protobuf.Int32Value":  checkedWrap(checkedInt),
		"google.protobuf.UInt64Value": checkedWrap(checkedUint),
		"google.protobuf.UInt32Value": checkedWrap(checkedUint),
		"google.protobuf.StringValue": checkedWrap(checkedString),

		"google.protobuf.Any":       checkedAny,
		"google.protobuf.Duration":  checkedDuration,
		"google.protobuf.Timestamp": checkedTimestamp,

		"google.protobuf.ListValue": checkedListDyn,
		"google.protobuf.NullValue": checkedNull,
		"google.protobuf.Struct":    checkedMapStringDyn,
		"google.protobuf.Value":     checkedDyn,
	}
)

Functions

This section is empty.

Types

type EnumDescription

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

EnumDescription maps a qualified enum name to its numeric value.

func DescribeEnum

func DescribeEnum(enumName string) (*EnumDescription, error)

DescribeEnum takes a qualified enum name and returns an EnumDescription.

func (*EnumDescription) Name

func (ed *EnumDescription) Name() string

Name of the enum.

func (*EnumDescription) Value

func (ed *EnumDescription) Value() int32

Value (numeric) of the enum.

type FieldDescription

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

FieldDescription holds metadata related to fields declared within a type.

func (*FieldDescription) CheckedType

func (fd *FieldDescription) CheckedType() *exprpb.Type

CheckedType returns the type-definition used at type-check time.

func (*FieldDescription) GetterName

func (fd *FieldDescription) GetterName() string

GetterName returns the accessor method name associated with the field on the proto generated struct.

func (*FieldDescription) Index

func (fd *FieldDescription) Index() int

Index returns the field index within a reflected value.

func (*FieldDescription) IsEnum

func (fd *FieldDescription) IsEnum() bool

IsEnum returns true if the field type refers to an enum value.

func (*FieldDescription) IsMap

func (fd *FieldDescription) IsMap() bool

IsMap returns true if the field is of map type.

func (*FieldDescription) IsMessage

func (fd *FieldDescription) IsMessage() bool

IsMessage returns true if the field is of message type.

func (*FieldDescription) IsOneof

func (fd *FieldDescription) IsOneof() bool

IsOneof returns true if the field is declared within a oneof block.

func (*FieldDescription) IsRepeated

func (fd *FieldDescription) IsRepeated() bool

IsRepeated returns true if the field is a repeated value.

This method will also return true for map values, so check whether the field is also a map.

func (*FieldDescription) Name

func (fd *FieldDescription) Name() string

Name returns the CamelCase name of the field within the proto-based struct.

func (*FieldDescription) OneofType

func (fd *FieldDescription) OneofType() reflect.Type

OneofType returns the reflect.Type value of a oneof field.

Oneof field values are wrapped in a struct which contains one field whose value is a proto.Message.

func (*FieldDescription) OrigName

func (fd *FieldDescription) OrigName() string

OrigName returns the snake_case name of the field as it was declared within the proto. This is the same name format that is expected within expressions.

func (*FieldDescription) String

func (fd *FieldDescription) String() string

String returns a proto-like field definition string.

func (*FieldDescription) SupportsPresence

func (fd *FieldDescription) SupportsPresence() bool

SupportsPresence returns true if the field supports presence detection.

func (*FieldDescription) TypeName

func (fd *FieldDescription) TypeName() string

TypeName returns the type name of the field.

type FileDescription

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

FileDescription holds a map of all types and enums declared within a .proto file.

func DescribeFile

func DescribeFile(message proto.Message) (*FileDescription, error)

DescribeFile takes a protocol buffer message and indexes all of the message types and enum values contained within the message's file descriptor.

func (*FileDescription) GetEnumDescription

func (fd *FileDescription) GetEnumDescription(enumName string) (*EnumDescription, error)

GetEnumDescription returns an EnumDescription for a qualified enum value name declared within the .proto file.

func (*FileDescription) GetEnumNames

func (fd *FileDescription) GetEnumNames() []string

GetEnumNames returns the string names of all enum values in the file.

func (*FileDescription) GetTypeDescription

func (fd *FileDescription) GetTypeDescription(typeName string) (*TypeDescription, error)

GetTypeDescription returns a TypeDescription for a qualified type name declared within the .proto file.

func (*FileDescription) GetTypeNames

func (fd *FileDescription) GetTypeNames() []string

GetTypeNames returns the list of all type names contained within the file.

func (*FileDescription) Package

func (fd *FileDescription) Package() string

Package returns the file's qualified package name.

type TypeDescription

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

TypeDescription is a collection of type metadata relevant to expression checking and evaluation.

func DescribeType

func DescribeType(typeName string) (*TypeDescription, error)

DescribeType provides a TypeDescription given a qualified type name.

func DescribeValue

func DescribeValue(value proto.Message) (*TypeDescription, error)

DescribeValue takes an instance of a protocol buffer message and returns the associated TypeDescription.

func (*TypeDescription) FieldByName

func (td *TypeDescription) FieldByName(name string) (*FieldDescription, bool)

FieldByName returns the FieldDescription associated with a field name.

func (*TypeDescription) FieldCount

func (td *TypeDescription) FieldCount() int

FieldCount returns the number of fields declared within the type.

func (*TypeDescription) FieldNameAtIndex

func (td *TypeDescription) FieldNameAtIndex(index int, refObj reflect.Value) (string, bool)

FieldNameAtIndex returns the field name at the specified index.

For oneof field values, multiple fields may exist at the same index, so the appropriate oneof getter's must be invoked in order to determine which of oneof fields is currently set at the index.

func (*TypeDescription) Name

func (td *TypeDescription) Name() string

Name of the type.

func (*TypeDescription) ReflectType

func (td *TypeDescription) ReflectType() reflect.Type

ReflectType returns the reflected struct type of the generated proto struct.

Jump to

Keyboard shortcuts

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