protobuf: github.com/golang/protobuf/ptypes Index | Files | Directories

package ptypes

import "github.com/golang/protobuf/ptypes"

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

Index

Package Files

any.go doc.go duration.go timestamp.go

func AnyMessageName Uses

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 Uses

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 Uses

func DurationProto(d time.Duration) *durpb.Duration

DurationProto converts a time.Duration to a durpb.Duration.

func Empty Uses

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 Uses

func Is(any *any.Any, pb proto.Message) bool

Is returns true if any value contains a given message type.

func MarshalAny Uses

func MarshalAny(pb proto.Message) (*any.Any, error)

MarshalAny takes the protocol buffer and encodes it into google.protobuf.Any.

func Timestamp Uses

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 Uses

func TimestampNow() *tspb.Timestamp

TimestampNow returns a google.protobuf.Timestamp for the current time.

func TimestampProto Uses

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 Uses

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 Uses

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 Uses

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

PathSynopsis
any
duration
empty
struct
timestamp
wrappers

Package ptypes imports 9 packages (graph) and is imported by 559 packages. Updated 2018-09-28. Refresh now. Tools for package owners.