Movatterモバイル変換


[0]ホーム

URL:


text

package
v1.36.11Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2025 License:BSD-3-ClauseImports:14Imported by:0

Details

Repository

github.com/protocolbuffers/protobuf-go

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

Constants

This section is empty.

Variables

View Source
var ErrUnexpectedEOF =errors.New("%v",io.ErrUnexpectedEOF)

ErrUnexpectedEOF means that EOF was encountered in the middle of the input.

Functions

funcAppendStringadded inv1.27.0

func AppendString(b []byte, sstring) []byte

AppendString appends the escaped form of the input string to b.

funcTokenEquals

func TokenEquals(x, yToken)bool

TokenEquals returns true if given Tokens are equal, else false.

funcUnmarshalString

func UnmarshalString(sstring) (string,error)

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

func NewDecoder(b []byte) *Decoder

NewDecoder returns a Decoder to read the given []byte.

func (*Decoder)Peek

func (d *Decoder) Peek() (Token,error)

Peek looks ahead and returns the next token and error without advancing a read.

func (*Decoder)Position

func (d *Decoder) Position(idxint) (lineint, columnint)

Position returns line and column number of given index of the original input.It will panic if index is out of range.

func (*Decoder)Read

func (d *Decoder) Read() (Token,error)

Read returns the next token.It will return an error if there is no valid token.

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

func NewEncoder(buf []byte, indentstring, delims [2]byte, outputASCIIbool) (*Encoder,error)

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)Bytes

func (e *Encoder) Bytes() []byte

Bytes returns the content of the written bytes.

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)WriteBool

func (e *Encoder) WriteBool(bbool)

WriteBool writes out the given boolean value.

func (*Encoder)WriteFloat

func (e *Encoder) WriteFloat(nfloat64, bitSizeint)

WriteFloat writes out the given float value for given bitSize.

func (*Encoder)WriteInt

func (e *Encoder) WriteInt(nint64)

WriteInt writes out the given signed integer value.

func (*Encoder)WriteLiteral

func (e *Encoder) WriteLiteral(sstring)

WriteLiteral writes out the given string as a literal value without quotes.This is used for writing enum literal strings.

func (*Encoder)WriteName

func (e *Encoder) WriteName(sstring)

WriteName writes out the field name and the separator ':'.

func (*Encoder)WriteString

func (e *Encoder) WriteString(sstring)

WriteString writes out the given string value.

func (*Encoder)WriteUint

func (e *Encoder) WriteUint(nuint64)

WriteUint writes out the given unsigned integer value.

typeKind

type Kinduint8

Kind represents a token kind expressible in the textproto format.

const (InvalidKind =iotaEOFName// Name indicates the field name.Scalar// Scalar are scalar values, e.g. "string", 47, ENUM_LITERAL, true.MessageOpenMessageCloseListOpenListClose)

Kind values.

func (Kind)String

func (tKind) String()string

typeNameKind

type NameKinduint8

NameKind represents different types of field names.

const (IdentNameNameKind =iota + 1TypeNameFieldNumber)

NameKind values.

func (NameKind)String

func (tNameKind) String()string

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)Bool

func (tToken) Bool() (bool,bool)

Bool returns the bool value for a Scalar type.

func (Token)Enum

func (tToken) Enum() (string,bool)

Enum returns the literal value for a Scalar type for use as enum literals.

func (Token)FieldNumber

func (tToken) FieldNumber()int32

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)Float32

func (tToken) Float32() (float32,bool)

Float32 returns the float32 value for a Scalar type.

func (Token)Float64

func (tToken) Float64() (float64,bool)

Float64 returns the float64 value for a Scalar type.

func (Token)HasSeparator

func (tToken) HasSeparator()bool

HasSeparator returns true if the field name is followed by the separator char':', else false. It panics if type is not Name.

func (Token)IdentName

func (tToken) IdentName()string

IdentName returns the value for IdentName type.

func (Token)Int32

func (tToken) Int32() (int32,bool)

Int32 returns the int32 value for a Scalar type.

func (Token)Int64

func (tToken) Int64() (int64,bool)

Int64 returns the int64 value for a Scalar type.

func (Token)Kind

func (tToken) Kind()Kind

Kind returns the token kind.

func (Token)NameKind

func (tToken) NameKind()NameKind

NameKind returns IdentName, TypeName or FieldNumber.It panics if type is not Name.

func (Token)Pos

func (tToken) Pos()int

Pos returns the token position from the input.

func (Token)RawString

func (tToken) RawString()string

RawString returns the read value in string.

func (Token)String

func (tToken) String() (string,bool)

String returns the string value for a Scalar type.

func (Token)TypeName

func (tToken) TypeName()string

TypeName returns the value for TypeName type.

func (Token)Uint32

func (tToken) Uint32() (uint32,bool)

Uint32 returns the uint32 value for a Scalar type.

func (Token)Uint64

func (tToken) Uint64() (uint64,bool)

Uint64 returns the uint64 value for a Scalar type.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp