encode

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2018 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package encode implements functions for encoding recordjar fields.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Boolean

func Boolean(b bool) []byte

Boolean returns the given boolean as a []byte containing either "TRUE" or "FALSE".

func Bytes

func Bytes(dataIn []byte) []byte

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

func DateTime(t time.Time) []byte

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

func Duration(d time.Duration) []byte

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

func Integer(i int) []byte

Integer returns the passed integer value as a stringified []byte.

func KeyedString added in v0.0.9

func KeyedString(name, value string, delimiter rune) (data []byte)

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

func KeyedStringList(pairs map[string]string, delimiter rune) (data []byte)

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

func Keyword(s string) []byte

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

func KeywordList(s []string) []byte

KeywordList returns the []string data as a whitespace separated, uppercased slice of bytes.

func PairList

func PairList(data map[string]string, delimiter rune) (pairs []byte)

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 String

func String(s string) []byte

String returns the given string as a []byte.

func StringList added in v0.0.9

func StringList(data []string) []byte

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

Jump to

Keyboard shortcuts

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