Protocol Buffers
// Protobuf writes a proto message to the client,
// which should be able to read and parse protos too.
Protobuf(v proto.Message) (int, error)
// ReadProtobuf binds the request body
// to the proto message.
ReadProtobuf(ptr proto.Message) error// JSON renders a proto.Message compatible value as JSON.
JSON(v interface{}, options ...JSON) (int, error)
// ReadJSONProtobuf reads a JSON body request
// into the given "ptr" proto.Message.
ReadJSONProtobuf(ptr proto.Message, opts ...protojson.UnmarshalOptions) errortype JSON struct {
// [...other fields]
Proto ProtoMarshalOptions
}
type ProtoMarshalOptions struct {
// Multiline specifies whether the marshaler
// should format the output in
// indented-form with every textual element
// on a new line.
// If Indent is an empty string,
// then an arbitrary indent is chosen.
Multiline bool
// Indent specifies the set of indentation
// characters to use in a multiline
// formatted output such that every entry
// is preceded by Indent and
// terminated by a newline. If non-empty,
// then Multiline is treated as true.
// Indent can only be composed of space or tab characters.
Indent string
// AllowPartial allows messages that have
// missing required fields to marshal
// without returning an error.
// If AllowPartial is false (the default),
// Marshal will return error if there are
// any missing required fields.
AllowPartial bool
// UseProtoNames uses proto field name
// instead of lowerCamelCase name in JSON
// field names.
UseProtoNames bool
// UseEnumNumbers emits enum values as numbers.
UseEnumNumbers bool
// EmitUnpopulated specifies whether to emit unpopulated fields.
// It does not emit unpopulated oneof fields
// or unpopulated extension fields.
// The JSON value emitted for unpopulated fields are as follows:
// βββββββββ€ββββββββββββββββββββββββββββ
// β JSON β Protobuf field
// β ββββββββͺββββββββββββββββββββββββββββ
// β false β proto3 boolean fields
// β 0 β proto3 numeric fields
// β "" β proto3 string/bytes fields
// β null β proto2 scalar fields
// β null β message fields
// β [] β list fields
// β {} β map fields
// βββββββββ§ββββββββββββββββββββββββββββ
EmitUnpopulated bool
}Example
Last updated
Was this helpful?