import "google.golang.org/protobuf/types/known/anypb"a, _ := anypb.New(&User{Id: "u1"})var u User_ = a.UnmarshalTo(&u)
Field
Purpose
type_url
Fully-qualified type URL (type.googleapis.com/pkg.Name)
value
Serialized message bytes
4. Using Struct Type
Field
Detail
fields
map<string, Value> — arbitrary JSON-like data
Use case
Schema-less payload, dynamic config
JSON
Native JSON object
5. Using Empty Type
Example: RPC with no input or output
import "google/protobuf/empty.proto";service Health { rpc Ping(google.protobuf.Empty) returns (google.protobuf.Empty);}
Note
Detail
Future-proof alt
Use a dedicated PingRequest{} so you can add fields later
6. Using FieldMask Type
Example: Partial update with FieldMask
import "google/protobuf/field_mask.proto";message UpdateUserRequest { User user = 1; google.protobuf.FieldMask update_mask = 2; // e.g. paths="email,profile.name"}
Field
Purpose
paths
List of field paths to update
Convention
Update only listed paths; ignore others
7. Using Wrapper Types
Wrapper
Wraps
Purpose
StringValue / BytesValue
string / bytes
Presence tracking
Int32/64Value, UInt32/64Value
integers
Distinguish 0 from unset
FloatValue / DoubleValue
float / double
Distinguish 0.0 from unset
BoolValue
bool
Distinguish false from unset
Note: Prefer optional over wrappers in proto3 — wrappers exist for legacy and JSON interop.