text

package module
v0.0.0-...-55f1d00 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: GPL-3.0 Imports: 9 Imported by: 7

README

Gophercraft Text Format

To keep the format simple and sane, it cannot deal with arbitrary data: data is parsed according to a known schema.

Example document

type Document struct {
  StringField string
  IntegerSlice []int
  Embedded    struct {
    Value float32
  }
}
{
  // Comments are allowed. C-style block comments are not yet implemented, but they may be in the future.
  StringField QuotesUnnecessary

  // Keys and values are both words. All words may be quoted.
  "IntegerSlice"
  {
    1
    2
    3
    "4" // Not a string, but can be quoted.
  }

  // Brackets are not always necessary to set a value in a struct.
  Embedded.Value 123.456
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

func Unmarshal

func Unmarshal(b []byte, v interface{}) error

Types

type Decoder

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

func NewDecoder

func NewDecoder(in io.Reader) *Decoder

func (*Decoder) Decode

func (decoder *Decoder) Decode(i interface{}) error

func (*Decoder) NextWord

func (decoder *Decoder) NextWord() (*Token, error)

type Encoder

type Encoder struct {
	Indent string
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder(out io.Writer) *Encoder

func (*Encoder) Encode

func (encoder *Encoder) Encode(i interface{}) error

type Token

type Token struct {
	Type TokenType
	Data string
}

type TokenType

type TokenType uint8
const (
	TokOpen TokenType = iota
	TokClose
	TokWord
)

type Word

type Word interface {
	EncodeWord() (string, error)
	DecodeWord(data string) error
}

Word describes custom data types that use one string. Useful for custom integral types

Jump to

Keyboard shortcuts

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