decode

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2017 License: BSD-2-Clause Imports: 5 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.

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 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) (pair [2]string)

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

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

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

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 [][2]string)

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.

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 date 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