text

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: GPL-3.0 Imports: 10 Imported by: 7

README

Gophercraft/text

Go Reference Chat on discord

The Gophercraft text format is used in Gophercraft for configuration and data interchange.

You can think about it as a more restricted version of JSON, but with comments

Another difference from JSON is that it cannot be used to represent arbitrary structures. Data must be serialized according to Go types.

Example document

type Document struct {
  StringField  string
  IntegerSlice []int
  Map          map[string]string
}
{
  /*
  *
  *
  * Block comments
  * 
  */
  
  // Or double-slash comments are allowed
  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.
  }

  Map
  {
    "Key" value
    other_key "another value"
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(value any) ([]byte, error)

func Unmarshal

func Unmarshal(b []byte, value any) error

Types

type Decoder

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

A Decoder reads and decodes text values from an input stream.

func NewDecoder

func NewDecoder(in io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r. The decoder introduces its own buffering and may read data from r beyond the text values requested.

func (*Decoder) Decode

func (decoder *Decoder) Decode(value any) 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(value any) error

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