lich

package module
v0.0.0-...-a25cd57 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2016 License: MIT Imports: 6 Imported by: 0

README

lich

A port of Wolf Rentzsch's Lich binary file format to Google Go. This is basically just an excuse for me to write some code in golang. If speed, efficiency, or completeness are a big deal for you, you should probably write your own module.

Todo

  • Add methods to turn lich data into regular Go-types.
  • Make an actual parser (!!)

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrUnexpectedClose = errors.New("Got unexpected close token")
	ErrMissingClose    = errors.New("Did not receive a close token")
	ErrBadKeyType      = errors.New("Lich dict key must be of type data")
)

Errors introduced during decoding

Functions

This section is empty.

Types

type Array

type Array []Element
Example
package main

import (
	"fmt"

	"github.com/carlmjohnson/lich"
)

func main() {
	array := lich.Array{lich.DataString("apple"), lich.DataString("banana"), lich.DataString("orange")}

	fmt.Println(array)
}
Output:
26[5<apple>6<banana>6<orange>]

func ArrayFromStrings

func ArrayFromStrings(strings ...string) Array
Example
package main

import (
	"fmt"

	"github.com/carlmjohnson/lich"
)

func main() {
	array := lich.ArrayFromStrings("simple", "general", "human-sympathetic")

	fmt.Println(array)
}
Output:
40[6<simple>7<general>17<human-sympathetic>]

func (Array) String

func (array Array) String() string

type DataString

type DataString string

func (DataString) String

func (data DataString) String() string

type Dict

type Dict map[DataString]Element
Example
package main

import (
	"fmt"

	"github.com/carlmjohnson/lich"
)

func main() {
	d1 := lich.Dict{
		"selling points": lich.ArrayFromStrings("simple", "general", "human-sympathetic"),
		"greeting":       lich.DataString([]byte{72, 101, 108, 108, 111}),
		"fruit":          lich.Array{lich.DataString("apple"), lich.DataString("banana"), lich.DataString("orange")},
	}

	fmt.Println(d1)
}
Output:
119{5<fruit>26[5<apple>6<banana>6<orange>]8<greeting>5<Hello>14<selling points>40[6<simple>7<general>17<human-sympathetic>]}

func DictFromMap

func DictFromMap(m map[string]interface{}) (Dict, error)
Example
package main

import (
	"fmt"

	"github.com/carlmjohnson/lich"
)

func main() {
	d2, _ := lich.DictFromMap(map[string]interface{}{
		"greeting": map[string]interface{}{
			"English":  []byte{72, 101, 108, 108, 111},
			"Japanese": "Konnichiwa",
		},
		"fruit":          []string{"apple", "banana", "orange"},
		"selling points": lich.ArrayFromStrings("simple", "general", "human-sympathetic"),
	})
	fmt.Println(d2)
}
Output:
158{5<fruit>26[5<apple>6<banana>6<orange>]8<greeting>43{7<English>5<Hello>8<Japanese>10<Konnichiwa>}14<selling points>40[6<simple>7<general>17<human-sympathetic>]}

func (Dict) String

func (d Dict) String() string

type Element

type Element interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

func Decode

func Decode(s string) (Element, error)

type UnknownTypeError

type UnknownTypeError struct {
	Key   string
	Value interface{}
}

DictFromMap returns an UnknownTypeError when it encounters values of an unknown type.

func (UnknownTypeError) Error

func (u UnknownTypeError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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