Any holds a message whose type isn't known when the schema is compiled.
google.protobuf.Any embeds an arbitrary serialized Protobuf message along with a URL that identifies its type, such as type.googleapis.com/mypackage.MyMessage.
In ProtoJSON, the type URL becomes a @type property alongside the embedded message's fields. A parser reads that property first to learn which message type the rest of the object holds. Decoding the embedded message requires that type's generated code or descriptor, usually looked up by URL in a type registry, and converting an Any to JSON fails when the type isn't registered.
The bytes carry the type URL as a plain string plus the serialized Note. That URL is the size cost of Any.
edition = "2024"; package demo.v1; import "google/protobuf/any.proto"; message Envelope { string kind = 1; google.protobuf.Any payload = 2; } message Note { string text = 1; }
Compiling the schema...
Next
The Value Type
Modeling schema-less, JSON-like data in Protobuf with google.protobuf.Value and Struct, and when to reach for them instead of Any.