ptypes

package
v0.0.0-...-1f49d83 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2016 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package ptypes contains code for interacting with well-known types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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.

Types

type DynamicAny

type DynamicAny struct {
	proto.Message
}

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)

Directories

Path Synopsis
Package any is a generated protocol buffer package.
Package any is a generated protocol buffer package.
Package duration is a generated protocol buffer package.
Package duration is a generated protocol buffer package.
Package empty is a generated protocol buffer package.
Package empty is a generated protocol buffer package.
Package structpb is a generated protocol buffer package.
Package structpb is a generated protocol buffer package.
Package timestamp is a generated protocol buffer package.
Package timestamp is a generated protocol buffer package.
Package wrappers is a generated protocol buffer package.
Package wrappers is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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