text
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package text implements the text format for protocol buffers.This package has no semantic understanding for protocol buffers and is onlya parser and composer for the format.
There is no formal specification for the protobuf text format, as such theC++ implementation (see google::protobuf::TextFormat) is the referenceimplementation of the text format.
This package is neither a superset nor a subset of the C++ implementation.This implementation permits a more liberal grammar in some cases to bebackwards compatible with the historical Go implementation.Future parsings unique to Go should not be added.Some grammars allowed by the C++ implementation are deliberatelynot implemented here because they are considered a bug by the protobuf teamand should not be replicated.
The Go implementation should implement a sufficient amount of the C++grammar such that the default text serialization by C++ can be parsed by Go.However, just because the C++ parser accepts some input does not mean thatthe Go implementation should as well.
The text format is almost a superset of JSON except:
- message keys are not quoted strings, but identifiers
- the top-level value must be a message without the delimiters
Index¶
- Variables
- func AppendString(b []byte, s string) []byte
- func TokenEquals(x, y Token) bool
- func UnmarshalString(s string) (string, error)
- type Decoder
- type Encoder
- func (e *Encoder) Bytes() []byte
- func (e *Encoder) EndMessage()
- func (e *Encoder) Reset(es encoderState)
- func (e *Encoder) Snapshot() encoderState
- func (e *Encoder) StartMessage()
- func (e *Encoder) WriteBool(b bool)
- func (e *Encoder) WriteFloat(n float64, bitSize int)
- func (e *Encoder) WriteInt(n int64)
- func (e *Encoder) WriteLiteral(s string)
- func (e *Encoder) WriteName(s string)
- func (e *Encoder) WriteString(s string)
- func (e *Encoder) WriteUint(n uint64)
- type Kind
- type NameKind
- type Token
- func (t Token) Bool() (bool, bool)
- func (t Token) Enum() (string, bool)
- func (t Token) FieldNumber() int32
- func (t Token) Float32() (float32, bool)
- func (t Token) Float64() (float64, bool)
- func (t Token) HasSeparator() bool
- func (t Token) IdentName() string
- func (t Token) Int32() (int32, bool)
- func (t Token) Int64() (int64, bool)
- func (t Token) Kind() Kind
- func (t Token) NameKind() NameKind
- func (t Token) Pos() int
- func (t Token) RawString() string
- func (t Token) String() (string, bool)
- func (t Token) TypeName() string
- func (t Token) Uint32() (uint32, bool)
- func (t Token) Uint64() (uint64, bool)
Constants¶
This section is empty.
Variables¶
var ErrUnexpectedEOF =errors.New("%v",io.ErrUnexpectedEOF)ErrUnexpectedEOF means that EOF was encountered in the middle of the input.
Functions¶
funcAppendString¶added inv1.27.0
AppendString appends the escaped form of the input string to b.
funcTokenEquals¶
TokenEquals returns true if given Tokens are equal, else false.
funcUnmarshalString¶
UnmarshalString returns an unescaped string given a textproto string value.String value needs to contain single or double quotes. This is only used byinternal/encoding/defval package for unmarshaling bytes.
Types¶
typeDecoder¶
type Decoder struct {// contains filtered or unexported fields}Decoder is a token-based textproto decoder.
funcNewDecoder¶
NewDecoder returns a Decoder to read the given []byte.
typeEncoder¶
type Encoder struct {// contains filtered or unexported fields}Encoder provides methods to write out textproto constructs and values. The user isresponsible for producing valid sequences of constructs and values.
funcNewEncoder¶
NewEncoder returns an Encoder.
If indent is a non-empty string, it causes every entry in a List or Messageto be preceded by the indent and trailed by a newline.
If delims is not the zero value, it controls the delimiter characters usedfor messages (e.g., "{}" vs "<>").
If outputASCII is true, strings will be serialized in such a way thatmulti-byte UTF-8 sequences are escaped. This property ensures that theoverall output is ASCII (as opposed to UTF-8).
func (*Encoder)EndMessage¶
func (e *Encoder) EndMessage()
EndMessage writes out the '}' or '>' symbol.
func (*Encoder)Reset¶
func (e *Encoder) Reset(es encoderState)
Reset resets the Encoder to the given encoderState from a Snapshot.
func (*Encoder)Snapshot¶
func (e *Encoder) Snapshot() encoderState
Snapshot returns the current snapshot for use in Reset.
func (*Encoder)StartMessage¶
func (e *Encoder) StartMessage()
StartMessage writes out the '{' or '<' symbol.
func (*Encoder)WriteFloat¶
WriteFloat writes out the given float value for given bitSize.
func (*Encoder)WriteLiteral¶
WriteLiteral writes out the given string as a literal value without quotes.This is used for writing enum literal strings.
func (*Encoder)WriteString¶
WriteString writes out the given string value.
typeKind¶
type Kinduint8
Kind represents a token kind expressible in the textproto format.
typeToken¶
type Token struct {// contains filtered or unexported fields}Token provides a parsed token kind and value. Values are provided by thedifferent accessor methods.
func (Token)FieldNumber¶
FieldNumber returns the value for FieldNumber type. It returns anon-negative int32 value. Caller will still need to validate for the correctfield number range.
func (Token)HasSeparator¶
HasSeparator returns true if the field name is followed by the separator char':', else false. It panics if type is not Name.
func (Token)NameKind¶
NameKind returns IdentName, TypeName or FieldNumber.It panics if type is not Name.