package ptypes
import "github.com/golang/protobuf/ptypes"
Package ptypes provides functionality for interacting with well-known types.
Deprecated: Well-known types have specialized functionality directly injected into the generated packages for each message type. See the deprecation notice for each function for the suggested alternative.
Index ¶
- func AnyMessageName(any *anypb.Any) (string, error)
- func Duration(dur *durationpb.Duration) (time.Duration, error)
- func DurationProto(d time.Duration) *durationpb.Duration
- func Empty(any *anypb.Any) (proto.Message, error)
- func Is(any *anypb.Any, m proto.Message) bool
- func MarshalAny(m proto.Message) (*anypb.Any, error)
- func Timestamp(ts *timestamppb.Timestamp) (time.Time, error)
- func TimestampNow() *timestamppb.Timestamp
- func TimestampProto(t time.Time) (*timestamppb.Timestamp, error)
- func TimestampString(ts *timestamppb.Timestamp) string
- func UnmarshalAny(any *anypb.Any, m proto.Message) error
- type DynamicAny
Functions ¶
func AnyMessageName ¶
AnyMessageName returns the message name contained in an anypb.Any message. Most type assertions should use the Is function instead.
Deprecated: Call the any.MessageName method instead.
func Duration ¶
func Duration(dur *durationpb.Duration) (time.Duration, error)
Duration converts a durationpb.Duration to a time.Duration. Duration returns an error if dur is invalid or overflows a time.Duration.
Deprecated: Call the dur.AsDuration and dur.CheckValid methods instead.
func DurationProto ¶
func DurationProto(d time.Duration) *durationpb.Duration
DurationProto converts a time.Duration to a durationpb.Duration.
Deprecated: Call the durationpb.New function instead.
func Empty ¶
Empty returns a new message of the type specified in an anypb.Any message. It returns protoregistry.NotFound if the corresponding message type could not be resolved in the global registry.
Deprecated: Use protoregistry.GlobalTypes.FindMessageByName instead to resolve the message name and create a new instance of it.
func Is ¶
Is reports whether the Any message contains a message of the specified type.
Deprecated: Call the any.MessageIs method instead.
func MarshalAny ¶
MarshalAny marshals the given message m into an anypb.Any message.
Deprecated: Call the anypb.New function instead.
func Timestamp ¶
func Timestamp(ts *timestamppb.Timestamp) (time.Time, error)
Timestamp converts a timestamppb.Timestamp 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.
Deprecated: Call the ts.AsTime and ts.CheckValid methods instead.
func TimestampNow ¶
func TimestampNow() *timestamppb.Timestamp
TimestampNow returns a google.protobuf.Timestamp for the current time.
Deprecated: Call the timestamppb.Now function instead.
func TimestampProto ¶
func TimestampProto(t time.Time) (*timestamppb.Timestamp, error)
TimestampProto converts the time.Time to a google.protobuf.Timestamp proto. It returns an error if the resulting Timestamp is invalid.
Deprecated: Call the timestamppb.New function instead.
func TimestampString ¶
func TimestampString(ts *timestamppb.Timestamp) string
TimestampString returns the RFC 3339 string for valid Timestamps. For invalid Timestamps, it returns an error message in parentheses.
Deprecated: Call the ts.AsTime method instead, followed by a call to the Format method on the time.Time value.
func UnmarshalAny ¶
UnmarshalAny unmarshals the encoded value contained in the anypb.Any message into the provided message m. It returns an error if the target message does not match the type in the Any message or if an unmarshal error occurs.
The target message m may be a *DynamicAny message. If the underlying message type could not be resolved, then this returns protoregistry.NotFound.
Deprecated: Call the any.UnmarshalTo method instead.
Types ¶
type DynamicAny ¶
DynamicAny is a value that can be passed to UnmarshalAny to automatically allocate a proto.Message for the type specified in an anypb.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)
Deprecated: Use the any.UnmarshalNew method instead to unmarshal the any message contents into a new instance of the underlying message.
func (DynamicAny) ProtoMessage ¶
func (m DynamicAny) ProtoMessage()
func (DynamicAny) ProtoReflect ¶
func (m DynamicAny) ProtoReflect() protoreflect.Message
func (DynamicAny) Reset ¶
func (m DynamicAny) Reset()
func (DynamicAny) String ¶
func (m DynamicAny) String() string
Source Files ¶
any.go doc.go duration.go timestamp.go
Directories ¶
Path | Synopsis |
---|---|
ptypes/any | |
ptypes/duration | |
ptypes/empty | |
ptypes/struct | |
ptypes/timestamp | |
ptypes/wrappers |
- Version
- v1.5.4 (latest)
- Published
- Mar 6, 2024
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 5 days ago –
Tools for package owners.