Documentation
¶
Overview ¶
Package decode implements functions for decoding recordjar fields.
Index ¶
- func Boolean(data []byte) (b bool)
- func Bytes(dataIn []byte) []byte
- func Duration(data []byte) (t time.Duration)
- func Integer(data []byte) (i int)
- func KeyedString(data []byte) (pair [2]string)
- func KeyedStringList(data []byte) (list [][2]string)
- func Keyword(data []byte) string
- func KeywordList(data []byte) []string
- func PairList(data []byte) (pairs [][2]string)
- func String(data []byte) string
- func StringList(data []byte) (s []string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Boolean ¶
Boolean returns the []byte data as a boolean value. The data is parsed using strconv.ParseBool and will default to false if the data cannot be parsed. Using strconv.parseBool allows true and false to be represented in many ways.
func Bytes ¶
Bytes returns a copy of the []byte data. Important so we don't accidentally pin a larger backing array in memory via the slice.
func Duration ¶
Duration returns the []byte data as a time.Duration. The data is parsed using time.ParseDuration and will default to 0 if the data cannot be parsed.
func Integer ¶
Integer returns the []byte data as an integer value. The []byte is parsed using strconv.Atoi and will default to 0 if the data cannot be parsed.
func KeyedString ¶
KeyedString returns the []byte data as an uppercassed keywrd and a string. The keyword is split from the beginning of the []byte on the first non-unicode letter or digit. For example:
input: []byte("GET→You can't get it.")
output: [2]string{"GET", "You can't get it."}
Here the separator used is → but any non-unicode letter or digit may be used.
func KeyedStringList ¶
KeyedStringList splits the []byte on a colon (:) separator and passes each result through KeyedString. KeyedStringList is a shorthand for combining StringList and KeyedString. For example the follow RecordJar record's data:
Vetoes: GET→You can't get it.
: DROP→You can't drop it.
Would produce a slice with two entries:
[2]string{"GET", "You can't get it."}
[2]string{"DROP", "You can't drop it."}
func Keyword ¶
Keyword returns the []bytes data as an uppercased string. This is helpful for keeping IDs and references consistent and independent of how they appear in e.g. data files.
func KeywordList ¶
KeywordList returns the []byte data as an uppercased slice of strings. The data is split on whitespace, extra whitespace is stripped and the individual 'words' are returned in the string slice.
func PairList ¶
PairList returns the []byte data as uppercassed pairs of strings in a slice. The data is first split on whitespace and extra whitespace is stripped. The 'words' are then split into pairs on the first non-unicode letter or digit. If we take exits as an example:
Exits: E→L3 SE→L4 S→ W
Results in four pairs:
[2]string{"E","L3"}
[2]string{"SE","L4"}
[2]string{"S",""}
[2]string{"W",""}
Here the separator used is → but any non-unicode letter or digit may be used.
Types ¶
This section is empty.
Source Files
¶
- decoder.go