text

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnexpectedEOF = fmt.Errorf("%w", io.ErrUnexpectedEOF)

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

Functions

func TokenEquals

func TokenEquals(x, y Token) bool

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

func UnmarshalI32

func UnmarshalI32(s string) (int32, bool)

UnmarshalI32 returns an i32 number forr given a textproto intlit value.

func UnmarshalString

func UnmarshalString(s string) (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 by internal/encoding/defval package for unmarshaling bytes.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder is a token-based textproto decoder.

func NewDecoder

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(idx int) (line int, column int)

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.

type Kind

type Kind uint8

Kind represents a token kind expressible in the textproto format.

const (
	Invalid Kind = iota
	EOF
	Name   // Name indicates the field name.
	Scalar // Scalar are scalar values, e.g. "string", 47, ENUM_LITERAL, true.
	MessageOpen
	MessageClose
	ListOpen
	ListClose
)

Kind values.

func (Kind) String

func (t Kind) String() string

type NameKind

type NameKind uint8

NameKind represents different types of field names.

const (
	IdentName NameKind = iota + 1
	TypeName
	FieldNumber
)

NameKind values.

func (NameKind) String

func (t NameKind) String() string

type Token

type Token struct {
	// contains filtered or unexported fields
}

Token provides a parsed token kind and value. Values are provided by the different accessor methods.

func (Token) Bool

func (t Token) Bool() (bool, bool)

Bool returns the bool value for a Scalar type.

func (Token) Enum

func (t Token) Enum() (string, bool)

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

func (Token) FieldNumber

func (t Token) FieldNumber() int32

FieldNumber returns the value for FieldNumber type. It returns a non-negative int32 value. Caller will still need to validate for the correct field number range.

func (Token) Float32

func (t Token) Float32() (float32, bool)

Float32 returns the float32 value for a Scalar type.

func (Token) Float64

func (t Token) Float64() (float64, bool)

Float64 returns the float64 value for a Scalar type.

func (Token) HasSeparator

func (t Token) 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 (t Token) IdentName() string

IdentName returns the value for IdentName type.

func (Token) Int32

func (t Token) Int32() (int32, bool)

Int32 returns the int32 value for a Scalar type.

func (Token) Int64

func (t Token) Int64() (int64, bool)

Int64 returns the int64 value for a Scalar type.

func (Token) Kind

func (t Token) Kind() Kind

Kind returns the token kind.

func (Token) NameKind

func (t Token) NameKind() NameKind

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

func (Token) Pos

func (t Token) Pos() int

Pos returns the token position from the input.

func (Token) RawString

func (t Token) RawString() string

RawString returns the read value in string.

func (Token) String

func (t Token) String() (string, bool)

String returns the string value for a Scalar type.

func (Token) TypeName

func (t Token) TypeName() string

TypeName returns the value for TypeName type.

func (Token) Uint32

func (t Token) Uint32() (uint32, bool)

Uint32 returns the uint32 value for a Scalar type.

func (Token) Uint64

func (t Token) Uint64() (uint64, bool)

Uint64 returns the uint64 value for a Scalar type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL