Any contains an arbitrary serialized protocol buffer message along with a
URL that describes the type of the serialized message.
Protobuf library provides support to pack/unpack Any values in the form
of utility functions or additional generated methods of the Any type.
Example 1: Pack and unpack a message in C++.
Foo foo = …;
Any any;
any.PackFrom(foo);
…
if (any.UnpackTo(&foo)) {
…
}
Example 2: Pack and unpack a message in Java.
Foo foo = …;
Any any = Any.pack(foo);
…
if (any.is(Foo.class)) {
foo = any.unpack(Foo.class);
}
// or …
if (any.isSameTypeAs(Foo.getDefaultInstance())) {
foo = any.unpack(Foo.getDefaultInstance());
}
Example 3: Pack and unpack a message in Python.
foo = Foo(…)
any = Any()
any.Pack(foo)
…
if any.Is(Foo.DESCRIPTOR):
any.Unpack(foo)
…
Example 4: Pack and unpack a message in Go
foo := &pb.Foo{…}
any, err := anypb.New(foo)
if err != nil {
…
}
…
foo := &pb.Foo{}
if err := any.UnmarshalTo(foo); err != nil {
…
}
The pack methods provided by protobuf library will by default use
‘type.googleapis.com/full.type.name’ as the type URL and the unpack
methods only use the fully qualified type name after the last ‘/’
in the type URL, for example “foo.bar.com/x/y.z” will yield type
name “y.z”.
JSON
Describes a message type.
A Duration represents a signed, fixed-length span of time represented
as a count of seconds and fractions of seconds at nanosecond
resolution. It is independent of any calendar and concepts like “day”
or “month”. It is related to Timestamp in that the difference between
two Timestamp values is a Duration and it can be added or subtracted
from a Timestamp. Range is approximately +-10,000 years.
A generic empty message that you can re-use to avoid defining duplicated
empty messages in your APIs. A typical example is to use it as the request
or the response type of an API method. For instance:
service Foo {
rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
}
Describes an enum type.
Describes a value within an enum.
TODO(b/274655146) Enums in C++ gencode (and potentially other languages) are
not well scoped. This means that each of the feature enums below can clash
with each other. The short names we’ve chosen maximize call-site
readability, but leave us very open to this scenario. A future feature will
be designed and implemented to handle this, hopefully before we ever hit a
conflict here.
Describes a field within a message.
Describes a complete .proto file.
The protocol compiler can output a FileDescriptorSet containing the .proto
files it parses.
Describes the relationship between generated code and its original source
file. A GeneratedCodeInfo message is associated with only one generated
source file, but may contain references to different source .proto files.
ListValue is a wrapper around a repeated field of values.
The JSON representation for ListValue is JSON array.
Describes a method of a service.
Describes a oneof.
Describes a service.
Encapsulates information about the original source file from which a
FileDescriptorProto was generated.
Struct represents a structured data value, consisting of fields
which map to dynamically typed values. In some languages, Struct
might be supported by a native representation. For example, in
scripting languages like JS a struct is represented as an
object. The details of that representation are described together
with the proto support for the language.
The JSON representation for Struct is JSON object.
A Timestamp represents a point in time independent of any time zone or local
calendar, encoded as a count of seconds and fractions of seconds at
nanosecond resolution. The count is relative to an epoch at UTC midnight on
January 1, 1970, in the proleptic Gregorian calendar which extends the
Gregorian calendar backwards to year one.
All minutes are 60 seconds long. Leap seconds are “smeared” so that no leap
second table is needed for interpretation, using a
24-hour linear
smear.
The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
restricting to that range, we ensure that we can convert to and from
RFC
3339 date strings.
A message representing a option the parser does not recognize. This only
appears in options protos created by the compiler::Parser class.
DescriptorPool resolves these when building Descriptor objects. Therefore,
options protos in descriptor objects (e.g. returned by Descriptor::options(),
or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
in them.
Value represents a dynamically typed value which can be either
null, a number, a string, a boolean, a recursive struct value, or a
list of values. A producer of value is expected to set one of these
variants. Absence of any variant indicates an error.
The JSON representation for Value is JSON value.