Involved Source Filesdecode.go
Package protojson marshals and unmarshals protocol buffer messages as JSON
format. It follows the guide at
https://developers.google.com/protocol-buffers/docs/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 7, in which 2 are exported)
/* sort exporteds 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.
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. It may change over time across
different versions of the program.
Marshal marshals the given proto.Message in the JSON format using options in
MarshalOptions. Do not depend on the output being stable. It may change over
time across different versions of the program.
marshal is a centralized function that all marshal operations go through.
For profiling purposes, avoid changing the name of this function or
introducing other code paths for marshal that do not go through this.
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 are ignored.
NoUnkeyedLiteralspragma.NoUnkeyedLiterals
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 UnmarshalOptions object. It will clear the message first before
setting the fields. If it returns an error, the given message may be
partially set.
unmarshal is a centralized function that all unmarshal operations go through.
For profiling purposes, avoid changing the name of this function or
introducing other code paths for unmarshal that do not go through this.
Decoder*json.Decoder
in contains the unconsumed input.
lastCall is last method called, either readCall or peekCall.
Initial value is readCall.
lastErr contains the last read error.
lastToken contains the last read token.
openStack is a stack containing ObjectOpen and ArrayOpen values. The
top of stack represents the object or the array the current value is
directly located in.
orig is used in reporting line and column.
optsUnmarshalOptions
Clone returns a copy of the Decoder for use in reading ahead the next JSON
object, array or other values without affecting current Decoder.
Peek looks ahead and returns the next token kind without advancing a read.
Position returns line and column number of given index of the original input.
It will panic if index is out of range.
Read returns the next JSON token.
It will return an error if there is no valid token.
consume consumes n bytes of input and any subsequent whitespace.
consumeBoolToken constructs a Token for a Bool kind with raw value derived from
current d.in and given size.
consumeStringToken constructs a Token for a String kind with raw value derived
from current d.in and given size.
consumeToken constructs a Token for given Kind with raw value derived from
current d.in and given size, and consumes the given size-lenght of it.
currPos returns the current index position of d.in from d.orig.
findExtension returns protoreflect.ExtensionType from the resolver if found.
isValueNext returns true if next type should be a JSON value: Null,
Number, String or Bool.
newError returns an error object with position info.
newSyntaxError returns an error with line and column information useful for
syntax errors.
parseNext parses for the next JSON token. It returns a Token object for
different types, except for Name. It does not handle whether the next token
is in a valid sequence or not.
( T) parseString(in []byte) (string, int, error)
skipJSONValue parses a JSON value (null, boolean, string, number, object and
array) in order to advance the read to the next JSON value. It relies on
the decoder returning an error if the types are not in valid sequence.
syntaxError returns a syntax error for given position.
unexpectedTokenError returns a syntax error for the given unexpected token.
( T) unmarshalAny(m pref.Message) error
unmarshalAnyValue unmarshals the given custom-type message from the JSON
object's "value" field.
( T) unmarshalDuration(m pref.Message) error( T) unmarshalEmpty(pref.Message) error( T) unmarshalFieldMask(m pref.Message) error
unmarshalFields unmarshals the fields into the given protoreflect.Message.
( T) unmarshalKnownValue(m pref.Message) error( T) unmarshalList(list pref.List, fd pref.FieldDescriptor) error( T) unmarshalListValue(m pref.Message) error( T) unmarshalMap(mmap pref.Map, fd pref.FieldDescriptor) error
unmarshalMapKey converts given token of Name kind into a protoreflect.MapKey.
A map key type is any integral or string type.
unmarshalMessage unmarshals a message into the given protoreflect.Message.
unmarshalScalar unmarshals to a scalar/enum protoreflect.Value specified by
the given FieldDescriptor.
unmarshalSingular unmarshals to the non-repeated field specified
by the given FieldDescriptor.
( T) unmarshalStruct(m pref.Message) error( T) unmarshalTimestamp(m pref.Message) error( T) unmarshalWrapperType(m pref.Message) error
func findTypeURL(d decoder) (json.Token, error)
Encoder*json.EncoderEncoder.indentstringEncoder.indents[]byteEncoder.lastKindjson.kindEncoder.out[]byteoptsMarshalOptions
Bytes returns the content of the written bytes.
EndArray writes out the ']' symbol.
EndObject writes out the '}' symbol.
StartArray writes out the '[' symbol.
StartObject writes out the '{' symbol.
WriteBool writes out the given boolean value.
WriteFloat writes out the given float and bitSize in JSON number value.
WriteInt writes out the given signed integer in JSON number value.
WriteName writes out the given string in JSON string value and the name
separator ':'. Returns error if input string contains invalid UTF-8, which
should not be likely as protobuf field names should be valid.
WriteNull writes out the null value.
WriteString writes out the given string in JSON string value. Returns error
if input string contains invalid UTF-8.
WriteUint writes out the given unsigned integer in JSON number value.
( T) marshalAny(m pref.Message) error( T) marshalDuration(m pref.Message) error( T) marshalEmpty(pref.Message) error
marshalExtensions marshals extension fields.
( T) marshalFieldMask(m pref.Message) error
marshalFields marshals the fields in the given protoreflect.Message.
( T) marshalKnownValue(m pref.Message) error
marshalList marshals the given protoreflect.List.
( T) marshalListValue(m pref.Message) error
marshalMap marshals given protoreflect.Map.
marshalMessage marshals the given protoreflect.Message.
marshalSingular marshals the given non-repeated field value. This includes
all scalar types, enums, messages, and groups.
( T) marshalStruct(m pref.Message) error( T) marshalTimestamp(m pref.Message) error
marshalValue marshals the given protoreflect.Value.
( T) marshalWrapperType(m pref.Message) error
prepareNext adds possible comma and indentation for the next value based
on last type and indent option. It also updates lastKind to next.
Package-Level Functions (total 18, in which 3 are exported)
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. It may change over time across
different versions of the program.
Marshal writes the given proto.Message in JSON format using default options.
Do not depend on the output being stable. It may change over time across
different versions of the program.
Unmarshal reads the given []byte into the given proto.Message.
findTypeURL returns the token for the "@type" field value from the given
JSON bytes. It is expected that the given bytes start with json.ObjectOpen.
It returns errEmptyObject if the JSON object is empty or errMissingType if
@type field does not exist. It returns other error if the @type field is not
valid or other decoding issues.
parseDuration parses the given input string for seconds and nanoseconds value
for the Duration JSON format. The format is a decimal number with a suffix
's'. It can have optional plus/minus sign. There needs to be at least an
integer or fractional part. Fractional part is limited to 9 digits only for
nanoseconds precision, regardless of whether there are trailing zero digits.
Example values are 1s, 0.1s, 1.s, .1s, +1s, -1s, -.1s.
sortMap orders list based on value of key field for deterministic ordering.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin 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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds.