google_protobuf

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package anypb contains generated types for google/protobuf/any.proto.

The Any message is a dynamic representation of any other message value. It is functionally a tuple of the full name of the remote message type and the serialized bytes of the remote message value.

Constructing an Any

An Any message containing another message value is constructed using New:

any, err := anypb.New(m)
if err != nil {
	... // handle error
}
... // make use of any

Unmarshaling an Any

With a populated Any message, the underlying message can be serialized into a remote concrete message value in a few ways.

If the exact concrete type is known, then a new (or pre-existing) instance of that message can be passed to the UnmarshalTo method:

m := new(foopb.MyMessage)
if err := any.UnmarshalTo(m); err != nil {
	... // handle error
}
... // make use of m

If the exact concrete type is not known, then the UnmarshalNew method can be used to unmarshal the contents into a new instance of the remote message type:

m, err := any.UnmarshalNew()
if err != nil {
	... // handle error
}
... // make use of m

UnmarshalNew uses the global type registry to resolve the message type and construct a new instance of that message to unmarshal into. In order for a message type to appear in the global registry, the Go type representing that protobuf message type must be linked into the Go binary. For messages generated by protoc-gen-go, this is achieved through an import of the generated Go package representing a .proto file.

A common pattern with UnmarshalNew is to use a type switch with the resulting proto.Message value:

switch m := m.(type) {
case *foopb.MyMessage:
	... // make use of m as a *foopb.MyMessage
case *barpb.OtherMessage:
	... // make use of m as a *barpb.OtherMessage
case *bazpb.SomeMessage:
	... // make use of m as a *bazpb.SomeMessage
}

This pattern ensures that the generated packages containing the message types listed in the case clauses are linked into the Go binary and therefore also registered in the global registry.

TypeSpec checking an Any

In order to type check whether an Any message represents some other message, then use the MessageIs method:

if any.MessageIs((*foopb.MyMessage)(nil)) {
	... // make use of any, knowing that it contains a foopb.MyMessage
}

The MessageIs method can also be used with an allocated instance of the target message type if the intention is to unmarshal into it if the type matches:

m := new(foopb.MyMessage)
if any.MessageIs(m) {
	if err := any.UnmarshalTo(m); err != nil {
		... // handle error
	}
	... // make use of m
}

Index

Constants

This section is empty.

Variables

View Source
var File_google_protobuf_any_proto protoreflect.FileDescriptor
View Source
var File_google_protobuf_empty_proto protoreflect.FileDescriptor
View Source
var File_google_protobuf_wrappers_proto protoreflect.FileDescriptor

Functions

func MarshalFrom

func MarshalFrom(dst *Any, src proto1.Message, opts proto1.MarshalOptions) error

MarshalFrom marshals src into dst as the underlying message using the provided marshal options.

If no options are specified, call dst.MarshalFrom instead.

func UnmarshalNew

func UnmarshalNew(src *Any, opts proto1.UnmarshalOptions) (dst proto1.Message, err error)

UnmarshalNew unmarshals the underlying message from src into dst, which is newly created message using a type resolved from the type URL. The message type is resolved according to opt.Resolver, which should implement protoregistry.MessageTypeResolver. It reports an error if the underlying message type could not be resolved.

If no options are specified, call src.UnmarshalNew instead.

func UnmarshalTo

func UnmarshalTo(src *Any, dst proto1.Message, opts proto1.UnmarshalOptions) error

UnmarshalTo unmarshals the underlying message from src into dst using the provided unmarshal options. It reports an error if dst is not of the right message type.

If no options are specified, call src.UnmarshalTo instead.

Types

type Any

type Any struct {
	TypeUrl string `protobuf:"bytes,1,opt,name=type_url,json=typeUrl,proto3" json:"type_url,omitempty"`
	Value   []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

Any contains an arbitrary serialized protocol buffer message along with a // URL that describes the type of the serialized message. client uses type `ArrayBuffer` for the value field . https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto

func New

func New(src proto1.Message) (*Any, error)

New marshals src into a new Any instance.

func (*Any) Descriptor deprecated

func (*Any) Descriptor() ([]byte, []int)

Deprecated: Use Any.ProtoReflect.Descriptor instead.

func (*Any) GetTypeUrl

func (x *Any) GetTypeUrl() string

func (*Any) GetValue

func (x *Any) GetValue() []byte

func (*Any) MarshalFrom

func (x *Any) MarshalFrom(m proto1.Message) error

MarshalFrom marshals m into x as the underlying message.

func (*Any) MessageIs

func (x *Any) MessageIs(m proto1.Message) bool

MessageIs reports whether the underlying message is of the same type as m.

func (*Any) MessageName

func (x *Any) MessageName() protoreflect.FullName

MessageName reports the full name of the underlying message, returning an empty string if invalid.

func (*Any) ProtoMessage

func (*Any) ProtoMessage()

func (*Any) ProtoReflect

func (x *Any) ProtoReflect() protoreflect.Message

func (*Any) Reset

func (x *Any) Reset()

func (*Any) String

func (x *Any) String() string

func (*Any) UnmarshalNew

func (x *Any) UnmarshalNew() (proto1.Message, error)

UnmarshalNew unmarshals the contents of the underlying message of x into a newly allocated message of the specified type. It reports an error if the underlying message type could not be resolved.

func (*Any) UnmarshalTo

func (x *Any) UnmarshalTo(m proto1.Message) error

UnmarshalTo unmarshals the contents of the underlying message of x into m. It resets m before performing the unmarshal operation. It reports an error if m is not of the right message type.

type BoolValue

type BoolValue struct {

	// The JSON representation for `BoolValue` is JSON `true` and `false`
	Value bool `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

Wrapper message for `bool`. https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto

func Bool

func Bool(v bool) *BoolValue

Bool stores v in a new BoolValue and returns a pointer to it.

func (*BoolValue) Descriptor deprecated

func (*BoolValue) Descriptor() ([]byte, []int)

Deprecated: Use BoolValue.ProtoReflect.Descriptor instead.

func (*BoolValue) GetValue

func (x *BoolValue) GetValue() bool

func (*BoolValue) ProtoMessage

func (*BoolValue) ProtoMessage()

func (*BoolValue) ProtoReflect

func (x *BoolValue) ProtoReflect() protoreflect.Message

func (*BoolValue) Reset

func (x *BoolValue) Reset()

func (*BoolValue) String

func (x *BoolValue) String() string

type BytesValue

type BytesValue struct {

	// The JSON representation for `BytesValue` is JSON string
	Value []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

Wrapper message for `bytes`. https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto

func Bytes

func Bytes(v []byte) *BytesValue

Bytes stores v in a new BytesValue and returns a pointer to it.

func (*BytesValue) Descriptor deprecated

func (*BytesValue) Descriptor() ([]byte, []int)

Deprecated: Use BytesValue.ProtoReflect.Descriptor instead.

func (*BytesValue) GetValue

func (x *BytesValue) GetValue() []byte

func (*BytesValue) ProtoMessage

func (*BytesValue) ProtoMessage()

func (*BytesValue) ProtoReflect

func (x *BytesValue) ProtoReflect() protoreflect.Message

func (*BytesValue) Reset

func (x *BytesValue) Reset()

func (*BytesValue) String

func (x *BytesValue) String() string

type DoubleValue

type DoubleValue struct {

	// The JSON representation for `DoubleValue` is JSON number
	Value float64 `protobuf:"fixed64,1,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

Wrapper message for `double`. https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto

func Double

func Double(v float64) *DoubleValue

Double stores v in a new DoubleValue and returns a pointer to it.

func (*DoubleValue) Descriptor deprecated

func (*DoubleValue) Descriptor() ([]byte, []int)

Deprecated: Use DoubleValue.ProtoReflect.Descriptor instead.

func (*DoubleValue) GetValue

func (x *DoubleValue) GetValue() float64

func (*DoubleValue) ProtoMessage

func (*DoubleValue) ProtoMessage()

func (*DoubleValue) ProtoReflect

func (x *DoubleValue) ProtoReflect() protoreflect.Message

func (*DoubleValue) Reset

func (x *DoubleValue) Reset()

func (*DoubleValue) String

func (x *DoubleValue) String() string

type Empty

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

https://github.com/protocolbuffers/protobuf/blob/master/src/protobuf/empty.proto

func (*Empty) Descriptor deprecated

func (*Empty) Descriptor() ([]byte, []int)

Deprecated: Use Empty.ProtoReflect.Descriptor instead.

func (*Empty) ProtoMessage

func (*Empty) ProtoMessage()

func (*Empty) ProtoReflect

func (x *Empty) ProtoReflect() protoreflect.Message

func (*Empty) Reset

func (x *Empty) Reset()

func (*Empty) String

func (x *Empty) String() string

type FloatValue

type FloatValue struct {

	// The JSON representation for `FloatValue` is JSON number
	Value float32 `protobuf:"fixed32,1,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

Wrapper message for `float`. https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto

func Float

func Float(v float32) *FloatValue

Float stores v in a new FloatValue and returns a pointer to it.

func (*FloatValue) Descriptor deprecated

func (*FloatValue) Descriptor() ([]byte, []int)

Deprecated: Use FloatValue.ProtoReflect.Descriptor instead.

func (*FloatValue) GetValue

func (x *FloatValue) GetValue() float32

func (*FloatValue) ProtoMessage

func (*FloatValue) ProtoMessage()

func (*FloatValue) ProtoReflect

func (x *FloatValue) ProtoReflect() protoreflect.Message

func (*FloatValue) Reset

func (x *FloatValue) Reset()

func (*FloatValue) String

func (x *FloatValue) String() string

type Int32Value

type Int32Value struct {

	// The JSON representation for `Int32Value` is JSON number
	Value int32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

Wrapper message for `int32`. https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto

func Int32

func Int32(v int32) *Int32Value

Int32 stores v in a new Int32Value and returns a pointer to it.

func (*Int32Value) Descriptor deprecated

func (*Int32Value) Descriptor() ([]byte, []int)

Deprecated: Use Int32Value.ProtoReflect.Descriptor instead.

func (*Int32Value) GetValue

func (x *Int32Value) GetValue() int32

func (*Int32Value) ProtoMessage

func (*Int32Value) ProtoMessage()

func (*Int32Value) ProtoReflect

func (x *Int32Value) ProtoReflect() protoreflect.Message

func (*Int32Value) Reset

func (x *Int32Value) Reset()

func (*Int32Value) String

func (x *Int32Value) String() string

type Int64Value

type Int64Value struct {

	// The JSON representation for `Int64Value` is JSON string
	Value int64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

Wrapper message for `int64`. https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto

func Int64

func Int64(v int64) *Int64Value

Int64 stores v in a new Int64Value and returns a pointer to it.

func (*Int64Value) Descriptor deprecated

func (*Int64Value) Descriptor() ([]byte, []int)

Deprecated: Use Int64Value.ProtoReflect.Descriptor instead.

func (*Int64Value) GetValue

func (x *Int64Value) GetValue() int64

func (*Int64Value) ProtoMessage

func (*Int64Value) ProtoMessage()

func (*Int64Value) ProtoReflect

func (x *Int64Value) ProtoReflect() protoreflect.Message

func (*Int64Value) Reset

func (x *Int64Value) Reset()

func (*Int64Value) String

func (x *Int64Value) String() string

type StringValue

type StringValue struct {

	// The JSON representation for `StringValue` is JSON string
	Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

Wrapper message for `string`. https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto

func String

func String(v string) *StringValue

String stores v in a new StringValue and returns a pointer to it.

func (*StringValue) Descriptor deprecated

func (*StringValue) Descriptor() ([]byte, []int)

Deprecated: Use StringValue.ProtoReflect.Descriptor instead.

func (*StringValue) GetValue

func (x *StringValue) GetValue() string

func (*StringValue) ProtoMessage

func (*StringValue) ProtoMessage()

func (*StringValue) ProtoReflect

func (x *StringValue) ProtoReflect() protoreflect.Message

func (*StringValue) Reset

func (x *StringValue) Reset()

func (*StringValue) String

func (x *StringValue) String() string

type UInt32Value

type UInt32Value struct {

	// The JSON representation for `UInt32Value` is JSON number
	Value uint32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

Wrapper message for `uint32`. https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto

func UInt32

func UInt32(v uint32) *UInt32Value

UInt32 stores v in a new UInt32Value and returns a pointer to it.

func (*UInt32Value) Descriptor deprecated

func (*UInt32Value) Descriptor() ([]byte, []int)

Deprecated: Use UInt32Value.ProtoReflect.Descriptor instead.

func (*UInt32Value) GetValue

func (x *UInt32Value) GetValue() uint32

func (*UInt32Value) ProtoMessage

func (*UInt32Value) ProtoMessage()

func (*UInt32Value) ProtoReflect

func (x *UInt32Value) ProtoReflect() protoreflect.Message

func (*UInt32Value) Reset

func (x *UInt32Value) Reset()

func (*UInt32Value) String

func (x *UInt32Value) String() string

type UInt64Value

type UInt64Value struct {

	// The JSON representation for `UInt64Value` is JSON string
	Value uint64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

Wrapper message for `uint64`. https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto

func UInt64

func UInt64(v uint64) *UInt64Value

UInt64 stores v in a new UInt64Value and returns a pointer to it.

func (*UInt64Value) Descriptor deprecated

func (*UInt64Value) Descriptor() ([]byte, []int)

Deprecated: Use UInt64Value.ProtoReflect.Descriptor instead.

func (*UInt64Value) GetValue

func (x *UInt64Value) GetValue() uint64

func (*UInt64Value) ProtoMessage

func (*UInt64Value) ProtoMessage()

func (*UInt64Value) ProtoReflect

func (x *UInt64Value) ProtoReflect() protoreflect.Message

func (*UInt64Value) Reset

func (x *UInt64Value) Reset()

func (*UInt64Value) String

func (x *UInt64Value) String() string

Directories

Path Synopsis
types

Jump to

Keyboard shortcuts

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