Package ptypes
Overview ▹
Index ▹
func AnyMessageName ¶
func AnyMessageName(any *any.Any) (string, error)
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 ¶
func Duration(p *durpb.Duration) (time.Duration, error)
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 ¶
func DurationProto(d time.Duration) *durpb.Duration
DurationProto converts a time.Duration to a durpb.Duration.
func Empty ¶
func Empty(any *any.Any) (proto.Message, error)
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 ¶
func Is(any *any.Any, pb proto.Message) bool
Is returns true if any value contains a given message type.
func MarshalAny ¶
func MarshalAny(pb proto.Message) (*any.Any, error)
MarshalAny takes the protocol buffer and encodes it into google.protobuf.Any.
func Timestamp ¶
func Timestamp(ts *tspb.Timestamp) (time.Time, error)
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 ¶
func TimestampNow() *tspb.Timestamp
TimestampNow returns a google.protobuf.Timestamp for the current time.
func TimestampProto ¶
func TimestampProto(t time.Time) (*tspb.Timestamp, error)
TimestampProto converts the time.Time to a google.protobuf.Timestamp proto. It returns an error if the resulting Timestamp is invalid.
func TimestampString ¶
func TimestampString(ts *tspb.Timestamp) string
TimestampString returns the RFC 3339 string for valid Timestamps. For invalid Timestamps, it returns an error message in parentheses.
func UnmarshalAny ¶
func UnmarshalAny(any *any.Any, pb proto.Message) error
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.
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)
type DynamicAny struct { proto.Message }
Subdirectories
Name | Synopsis |
---|---|
.. | |
any | Package any is a generated protocol buffer package. |
duration | Package duration is a generated protocol buffer package. |
empty | Package empty is a generated protocol buffer package. |
struct | Package structpb is a generated protocol buffer package. |
timestamp | Package timestamp is a generated protocol buffer package. |
wrappers | Package wrappers is a generated protocol buffer package. |