Documentation ¶
Overview ¶
Package ptypes contains code for interacting with well-known types.
Index ¶
- func AnyMessageName(any *any.Any) (string, error)
- func Duration(p *durpb.Duration) (time.Duration, error)
- func DurationProto(d time.Duration) *durpb.Duration
- func Empty(any *any.Any) (proto.Message, error)
- func Is(any *any.Any, pb proto.Message) bool
- func MarshalAny(pb proto.Message) (*any.Any, error)
- func Timestamp(ts *tspb.Timestamp) (time.Time, error)
- func TimestampNow() *tspb.Timestamp
- func TimestampProto(t time.Time) (*tspb.Timestamp, error)
- func TimestampString(ts *tspb.Timestamp) string
- func UnmarshalAny(any *any.Any, pb proto.Message) error
- type DynamicAny
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyMessageName ¶
AnyMessageName returns the name of the message contained in a google.protobuf.Any message.
Note that regular type assertions should be done using the Is function. AnyMessageName is provided for less common use cases like filtering a sequence of Any messages based on a set of allowed message type names.
func Duration ¶
Duration converts a durpb.Duration to a time.Duration. Duration returns an error if the durpb.Duration is invalid or is too large to be represented in a time.Duration.
func DurationProto ¶
DurationProto converts a time.Duration to a durpb.Duration.
func Empty ¶
Empty returns a new proto.Message of the type specified in a google.protobuf.Any message. It returns an error if corresponding message type isn't linked in.
func Is ¶
Is returns true if any value contains a given message type.
func MarshalAny ¶
MarshalAny takes the protocol buffer and encodes it into google.protobuf.Any.
func Timestamp ¶
Timestamp converts a google.protobuf.Timestamp proto to a time.Time. It returns an error if the argument is invalid.
Unlike most Go functions, if Timestamp returns an error, the first return value is not the zero time.Time. Instead, it is the value obtained from the time.Unix function when passed the contents of the Timestamp, in the UTC locale. This may or may not be a meaningful time; many invalid Timestamps do map to valid time.Times.
A nil Timestamp returns an error. The first return value in that case is undefined.
func TimestampNow ¶
TimestampNow returns a google.protobuf.Timestamp for the current time.
func TimestampProto ¶
TimestampProto converts the time.Time to a google.protobuf.Timestamp proto. It returns an error if the resulting Timestamp is invalid.
func TimestampString ¶
TimestampString returns the RFC 3339 string for valid Timestamps. For invalid Timestamps, it returns an error message in parentheses.
func UnmarshalAny ¶
UnmarshalAny parses the protocol buffer representation in a google.protobuf.Any message and places the decoded result in pb. It returns an error if type of contents of Any message does not match type of pb message.
pb can be a proto.Message, or a *DynamicAny.
Types ¶
type DynamicAny ¶
DynamicAny is a value that can be passed to UnmarshalAny to automatically allocate a proto.Message for the type specified in a google.protobuf.Any message. The allocated message is stored in the embedded proto.Message.
Example:
var x ptypes.DynamicAny if err := ptypes.UnmarshalAny(a, &x); err != nil { ... } fmt.Printf("unmarshaled message: %v", x.Message)