decode

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: 6 Imported by: 0

Documentation

Overview

Package decode implements functions for decoding recordjar fields.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Boolean

func Boolean(data []byte) (b bool)

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. As a special case data of length zero will default to true. This allows true to be represented as the presence or absence of just a keyword. For example:

Door: EXIT→E RESET→1m JITTER→1m OPEN

Here OPEN is a boolean and will default to true.

func Bytes

func Bytes(dataIn []byte) []byte

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 DateTime added in v0.0.9

func DateTime(data []byte) (t time.Time)

DateTime returns the []byte data as a time.Time. The data is parsed using time.Parse and is expected to conform to RFC1123 - as written by encode.DateTime. If there is an error parsing the data the date and time will default to the current date and time.

func Duration

func Duration(data []byte) (t time.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

func Integer(data []byte) (i int)

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

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

KeyedString returns the []byte data as an uppercassed keyword and a string value. 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: "GET", "You can't get it."

Here the separator used is → but any non-unicode letter or digit may be used.

func KeyedStringList

func KeyedStringList(data []byte) (list map[string]string)

KeyedStringList splits the []byte data into a map of keywords and strings. The []byte data is first split on a colon (:) separator to determine the pairs. The keyword is then split from the beginning of each pair on the first non-unicode letter or digit. For example:

Vetoes:  GET→You can't get it.
      : DROP→You can't drop it.

Would produce a map with two entries:

map[string]string{
  "GET": "You can't get it.",
  "DROP": "You can't drop it.",
}

func Keyword

func Keyword(data []byte) string

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

func KeywordList(data []byte) []string

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

func PairList(data []byte) (pairs map[string]string)

PairList returns the []byte data as uppercassed pairs of strings in a map. 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 a map with four pairs:

map[string]string {
  "E": "L3",
  "SE": "L4",
  "S": "",
  "W": "",
}

Here the separator used is → but any non-unicode letter or digit may be used.

func String

func String(data []byte) string

String returns the []bytes data as a string.

func StringList

func StringList(data []byte) (s []string)

StringList returns the []byte data as a []string by splitting the data on a colon separator.

Types

This section is empty.

Source Files

  • decoder.go

Jump to

Keyboard shortcuts

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