Involved Source Filesdecode.go
Package prototext marshals and unmarshals protocol buffer messages as the
textproto format.
encode.go
Package-Level Type Names (total 4, in which 2 are exported)
/* sort exporteds by: | */
MarshalOptions is a configurable text 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.
EmitASCII specifies whether to format strings and bytes as ASCII only
as opposed to using UTF-8 encoding when possible.
EmitUnknown specifies whether to emit unknown fields in the output.
If specified, the unmarshaler may be unable to parse the output.
The default is to exclude unknown 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.
allowInvalidUTF8 specifies whether to permit the encoding of strings
with invalid UTF-8. This is unexported as it is intended to only
be specified by the Format method.
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 writes the given proto.Message in textproto format using options in
MarshalOptions object. 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 textproto format unmarshaler.
AllowPartial accepts input for messages that will result in missing
required fields. If AllowPartial is false (the default), Unmarshal will
return error if there are any missing required fields.
DiscardUnknown specifies whether to ignore unknown fields when parsing.
An unknown field is any field whose field name or field number does not
resolve to any known or extension field in the message.
By default, unmarshal rejects unknown fields as an error.
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 the UnmarshalOptions object.
The provided message must be mutable (e.g., a non-nil pointer to a message).
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*text.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 the byte characters for MessageOpen and
ListOpen kinds. The top of stack represents the message or the list that
the current token is nested in. An empty stack means the current token is
at the top level message. The characters '{' and '<' both represent the
MessageOpen kind.
orig is used in reporting line and column.
optsUnmarshalOptions
Peek looks ahead and returns the next token and error 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 token.
It will return an error if there is no valid token.
consume consumes n bytes of input and any subsequent whitespace or comments.
consumeToken constructs a Token for given Kind from d.in and consumes given
size-length from it.
currentOpenKind indicates whether current position is inside a message, list
or top-level message by returning MessageOpen, ListOpen or bof respectively.
If the returned kind is either a MessageOpen or ListOpen, it also returns the
corresponding closing character.
newError returns an error object with position info.
newSyntaxError returns a syntax error with line and column information for
current position.
parseFieldName parses field name and separator.
parseLiteralValue parses a literal value. A literal value is used for
bools, special floats and enums. This function simply identifies that the
field value is a literal.
parseNext parses the next Token based on given last kind.
parseNumberValue parses a number from the input and returns a Token object.
parseScalar parses for a string, literal or number value.
parseString parses a string value enclosed in " or '.
parseStringValue parses string field token.
This differs from parseString since the text format allows
multiple back-to-back string literals where they are semantically treated
as a single large string with all values concatenated.
E.g., `"foo" "bar" "baz"` => "foobarbaz"
parseTypeName parses Any type URL or extension field name. The name is
enclosed in [ and ] characters. The C++ parser does not handle many legal URL
strings. This implementation is more liberal and allows for the pattern
^[-_a-zA-Z0-9]+([./][-_a-zA-Z0-9]+)*`). Whitespaces and comments are allowed
in between [ ], '.', '/' and the sub names.
( T) popOpenStack()( T) pushOpenStack(ch byte)
skipMessageValue makes the decoder parse and skip over all fields in a
message. It assumes that the previous read type is MessageOpen.
skipValue makes the decoder parse a field value in order to advance the read
to the next field. It relies on Read returning an error if the types are not
in valid sequence.
syntaxError returns a syntax error for given position.
( T) tryConsumeChar(c byte) bool
unexpectedTokenError returns a syntax error for the given unexpected token.
unmarshalAny unmarshals an Any textproto. It can either be in expanded form
or non-expanded form.
( T) unmarshalExpandedAny(typeURL string, pos int) ([]byte, error)
unmarshalList unmarshals into given protoreflect.List. A list value can
either be in [] syntax or simply just a single scalar/message value.
unmarshalMap unmarshals into given protoreflect.Map. A map value is a
textproto message containing {key: <kvalue>, value: <mvalue>}.
unmarshalMap unmarshals into given protoreflect.Map. A map value is a
textproto message containing {key: <kvalue>, value: <mvalue>}.
unmarshalMessage unmarshals into the given protoreflect.Message.
unmarshalScalar unmarshals a scalar/enum protoreflect.Value specified by the
given FieldDescriptor.
unmarshalSingular unmarshals a non-repeated field value specified by the
given FieldDescriptor.
Encoder*text.EncoderEncoder.delims[2]byteEncoder.encoderStatetext.encoderStateEncoder.encoderState.indents[]byteEncoder.encoderState.lastTypetext.encTypeEncoder.encoderState.out[]byteEncoder.indentstringEncoder.outputASCIIbooloptsMarshalOptions
Bytes returns the content of the written bytes.
EndMessage writes out the '}' or '>' symbol.
Reset resets the Encoder to the given encoderState from a Snapshot.
Snapshot returns the current snapshot for use in Reset.
StartMessage writes out the '{' or '<' symbol.
WriteBool writes out the given boolean value.
WriteFloat writes out the given float value for given bitSize.
WriteInt writes out the given signed integer value.
WriteLiteral writes out the given string as a literal value without quotes.
This is used for writing enum literal strings.
WriteName writes out the field name and the separator ':'.
WriteString writes out the given string value.
WriteUint writes out the given unsigned integer value.
marshalAny marshals the given google.protobuf.Any message in expanded form.
It returns true if it was able to marshal, else false.
marshalField marshals the given field with protoreflect.Value.
marshalList marshals the given protoreflect.List as multiple name-value fields.
marshalMap marshals the given protoreflect.Map as multiple name-value fields.
marshalMessage marshals the given protoreflect.Message.
marshalSingular marshals the given non-repeated field value. This includes
all scalar types, enums, messages, and groups.
marshalUnknown parses the given []byte and marshals fields out.
This function assumes proper encoding in the given []byte.
prepareNext adds possible space and indentation for the next value based
on last encType and indent option. It also updates e.lastType to next.
Package-Level Functions (total 3, all 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 textproto 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.
The provided message must be mutable (e.g., a non-nil pointer to a message).
Package-Level Constants (only one, which is unexported)
The pages are generated with Goldsv0.3.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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds.