type Decoder … // NewDecoder returns a Decoder to read the given []byte. func NewDecoder(b []byte) *Decoder { … } var ErrUnexpectedEOF … type call … const readCall … const peekCall … // Peek looks ahead and returns the next token and error without advancing a read. func (d *Decoder) Peek() (Token, error) { … } // Read returns the next token. // It will return an error if there is no valid token. func (d *Decoder) Read() (Token, error) { … } const mismatchedFmt … const unexpectedFmt … // parseNext parses the next Token based on given last kind. func (d *Decoder) parseNext(lastKind Kind) (Token, error) { … } var otherCloseChar … // 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. func (d *Decoder) currentOpenKind() (Kind, byte) { … } func (d *Decoder) pushOpenStack(ch byte) { … } func (d *Decoder) popOpenStack() { … } // parseFieldName parses field name and separator. func (d *Decoder) parseFieldName() (tok Token, err error) { … } // 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. func (d *Decoder) parseTypeName() (Token, error) { … } func isTypeNameChar(b byte) bool { … } func isWhiteSpace(b byte) bool { … } // parseIdent parses an unquoted proto identifier and returns size. // If allowNeg is true, it allows '-' to be the first character in the // identifier. This is used when parsing literal values like -infinity, etc. // Regular expression matches an identifier: `^[_a-zA-Z][_a-zA-Z0-9]*` func parseIdent(input []byte, allowNeg bool) int { … } // parseScalar parses for a string, literal or number value. func (d *Decoder) parseScalar() (Token, error) { … } // 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. func (d *Decoder) parseLiteralValue() (Token, bool) { … } // consumeToken constructs a Token for given Kind from d.in and consumes given // size-length from it. func (d *Decoder) consumeToken(kind Kind, size int, attrs uint8) Token { … } // newSyntaxError returns a syntax error with line and column information for // current position. func (d *Decoder) newSyntaxError(f string, x ...any) error { … } // Position returns line and column number of given index of the original input. // It will panic if index is out of range. func (d *Decoder) Position(idx int) (line int, column int) { … } func (d *Decoder) tryConsumeChar(c byte) bool { … } // consume consumes n bytes of input and any subsequent whitespace or comments. func (d *Decoder) consume(n int) { … } // consume consumes n bytes of input and any subsequent whitespace or comments. func consume(b []byte, n int) []byte { … } // errId extracts a byte sequence that looks like an invalid ID // (for the purposes of error reporting). func errId(seq []byte) []byte { … } // isDelim returns true if given byte is a delimiter character. func isDelim(c byte) bool { … }