Involved Source Filesdecode.go Package protojson marshals and unmarshals protocol buffer messages as JSON
format. It follows the guide at
https://protobuf.dev/programming-guides/proto3#json.
This package produces a different output than the standard [encoding/json]
package, which does not operate correctly on protocol buffer messages.encode.gowell_known_types.go
Package-Level Type Names (total 2)
/* sort by: | */
MarshalOptions is a configurable JSON format marshaler. 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. EmitDefaultValues specifies whether to emit default-valued primitive fields,
empty lists, and empty maps. The fields affected are as follows:
╔═══════╤════════════════════════════════════════╗
║ JSON │ Protobuf field ║
╠═══════╪════════════════════════════════════════╣
║ false │ non-optional scalar boolean fields ║
║ 0 │ non-optional scalar numeric fields ║
║ "" │ non-optional scalar string/byte fields ║
║ [] │ empty repeated fields ║
║ {} │ empty map fields ║
╚═══════╧════════════════════════════════════════╝
Behaves similarly to EmitUnpopulated, but does not emit "null"-value fields,
i.e. presence-sensing fields that are omitted will remain omitted to preserve
presence-sensing.
EmitUnpopulated takes precedence over EmitDefaultValues since the former generates
a strict superset of the latter. 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 ║
╚═══════╧════════════════════════════╝ 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. 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.NoUnkeyedLiteralspragma.NoUnkeyedLiterals Resolver is used for looking up types when expanding google.protobuf.Any
messages. If nil, this defaults to using protoregistry.GlobalTypes. UseEnumNumbers emits enum values as numbers. UseProtoNames uses proto field name instead of lowerCamelCase name in JSON
field names. Format formats the message as a string.
This method is only intended for human consumption and ignores errors.
Do not depend on the output being stable. Its output will change across
different builds of your program, even when using the same version of the
protobuf module. Marshal marshals the given [proto.Message] in the JSON format using options in
Do not depend on the output being stable. Its output will change across
different builds of your program, even when using the same version of the
protobuf module. MarshalAppend appends the JSON format encoding of m to b,
returning the result.
UnmarshalOptions is a configurable JSON format parser. If AllowPartial is set, input for messages that will result in missing
required fields will not return an error. If DiscardUnknown is set, unknown fields and enum name values are ignored.NoUnkeyedLiteralspragma.NoUnkeyedLiterals RecursionLimit limits how deeply messages may be nested.
If zero, a default limit is applied. Resolver is used for looking up types when unmarshaling
google.protobuf.Any messages or extension fields.
If nil, this defaults to using protoregistry.GlobalTypes. Unmarshal reads the given []byte and populates the given [proto.Message]
using options in the UnmarshalOptions object.
It will clear the message first before setting the fields.
If it returns an error, the given message may be partially set.
The provided message must be mutable (e.g., a non-nil pointer to a message).
Package-Level Functions (total 3)
Format formats the message as a multiline string.
This function is only intended for human consumption and ignores errors.
Do not depend on the output being stable. Its output will change across
different builds of your program, even when using the same version of the
protobuf module.
Marshal writes the given [proto.Message] in JSON format using default options.
Do not depend on the output being stable. Its output will change across
different builds of your program, even when using the same version of the
protobuf module.
Unmarshal reads the given []byte into the given [proto.Message].
The provided message must be mutable (e.g., a non-nil pointer to a message).
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.