Documentation
¶
Overview ¶
Package encode implements functions for encoding recordjar fields.
Index ¶
- func Boolean(b bool) []byte
- func Bytes(dataIn []byte) []byte
- func DateTime(t time.Time) []byte
- func Duration(d time.Duration) []byte
- func Integer(i int) []byte
- func KeyedString(name, value string, delimiter rune) (data []byte)
- func KeyedStringList(pairs map[string]string, delimiter rune) (data []byte)
- func Keyword(s string) []byte
- func KeywordList(s []string) []byte
- func PairList(data map[string]string, delimiter rune) (pairs []byte)
- func String(s string) []byte
- func StringList(data []string) []byte
- Bugs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Boolean ¶
Boolean returns the given boolean as a []byte containing either "TRUE" or "FALSE".
func Bytes ¶
Bytes returns a copy of the passed []byte. Important so we don't accidentally pin a larger backing array in memory via the slice.
func DateTime ¶
Duration returns the given time.Duration as a []byte. The byte slice will be formatted according to RFC1123. For example "Mon, 02 Jan 2006 15:04:05 MST".
func Duration ¶
Duration returns the given time.Duration as a []byte. The byte slice will have the format "0h0m0.0s" although leading and trailing zero units will be omitted.
func Integer ¶
Integer returns the passed integer value as a stringified []byte.
func KeyedString ¶ added in v0.0.9
KeyedString returns the name uppercased and concatenated to the value using the delimiter, as a []byte. For example:
KeyedString("get", "You cannot get that!", '→')
Results in a []byte containing "GET→You cannot get that!".
func KeyedStringList ¶ added in v0.0.9
KeyedStringList returns the map of names and strings as a list of colon separated keyed strings. For example:
m := map[string]string{
"get": "You cannot get that!",
"look": "Your eyes hurt to look at it!",
}
data := KeyedStringList(m, '→')
Results in data being a byte slice containing "GET→You cannot get that! : LOOK→Your eyes hurt to look at it!".
BUG(diddymus): The strings should be formatted with the separating colon starting on a new line with the colon aligned with the colon separating the keyword:
keyword: GET→You cannot get that!
: LOOK→Your eyes hurt to look at it!
However this is not currently possible and so the strings are simply concatenated together:
keyword: GET→You cannot get that! : LOOK→Your eyes hurt to look at it!
func Keyword ¶
Keyword returns the passed string as an uppercased []byte. 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 []string data as a whitespace separated, uppercased slice of bytes.
func PairList ¶
PairList returns the passed map of string pairs as an uppercased []byte. Each pair of strings is separated with the given delimiter. All of the string pairs are then concatenated together separated by whitespace.
exits := map[string]string{
"E": "L3",
"SE": "L4",
"S": "L2",
}
data := PairList(exits, '→')
Results in data being a byte slice containing "E→L3 SE→L4 S→L2".
func StringList ¶ added in v0.0.9
StringList returns a list of strings delimited by a colon separator.
BUG(diddymus): The strings should be formatted with the separating colon starting on a new line with the colon aligned with the colon separating the keyword:
keyword: String one
: String two
: String three
However this is not currently possible and so the strings are simply concatenated together:
keyword: String one : String two : String three
Types ¶
This section is empty.
Notes ¶
Bugs ¶
The strings should be formatted with the separating colon starting on a new line with the colon aligned with the colon separating the keyword:
keyword: String one : String two : String three
However this is not currently possible and so the strings are simply concatenated together:
keyword: String one : String two : String three
The strings should be formatted with the separating colon starting on a new line with the colon aligned with the colon separating the keyword:
keyword: GET→You cannot get that! : LOOK→Your eyes hurt to look at it!
However this is not currently possible and so the strings are simply concatenated together:
keyword: GET→You cannot get that! : LOOK→Your eyes hurt to look at it!
Source Files
¶
- encoder.go