dotquote

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2016 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

Package dotquote serializes data into the "dotquote" format.

The "dotquote" format is a more human-readable for a list of namespaced key-valued pairs.

The "dotquote" format is also useful for fitting your entire data on a single line of text.

Example

"app"."name"="myapi" "app"."build"."number"="23" "apple"="one" "banana"="two" "cherry"="three" "trace"."id"="DtehCQqBnw93Tw4h"

The example dotquote line could have been generated by the following code:

m := map[string]interface{}{
	"app":map[string]interface{}{
		"name":"myapi",
		"build":map[string]interface{
			"number":23,
		},
	},
	"apple":"one",
	"banana":"two",
	"cherry":"three",
	"trace":map[string]interface{}{
		"id":"DtehCQqBnw93Tw4h",
	},
}

var p []byte
p = dotquote.AppendMap(p, m)

Alternatively, it that example dotquote line could have been generated by the following code:

var p []byte

p = dotquote.AppendString(p, "myapi", "app", "name")
p = dotquote.AppendString(p, "23",    "app", "build", "number")
p = dotquote.AppendString(p, "one",   "apple")
p = dotquote.AppendString(p, "two",   "banana")
p = dotquote.AppendString(p, "three", "cherry")
p = dotquote.AppendString(p, "DtehCQqBnw93Tw4h", "trace", "id")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(p []byte, value []byte, name ...[]byte) []byte

func AppendMap

func AppendMap(p []byte, mapData map[string]interface{}, namePrefix ...string) []byte

func AppendString

func AppendString(p []byte, value string, name ...string) []byte

func AppendStrings

func AppendStrings(p []byte, value []string, name ...string) []byte

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal parses the dotquote-encoded data and stores the result in the value pointed to by v.

Types

type Decoder

type Decoder struct {
	Bytes  []byte
	Logger Logger
	// contains filtered or unexported fields
}

Decoder

Example usage:

decoder := Decoder{
	Bytes: p,
}

for decoder.Next() {
	keyBegin, keyEnd, err := decoder.Key()
	if nil != err {
		return err
	}

	key := p[keyBegin:keyEnd]

	//@TODO: do something with the key

	values := decoder.Values()
	for values.Next() {
		valueBegin, valueEnd, err := values.Value()
		if nil != err {
			return err
		}

		value := p[valueBegin:valueEnd]

		/?@TOD: do something with the value.
	}
	if err := values.Err(); nil != err {
		return err
	}
}
if err := decoder.Err(); nil != err {
	return nil
}

func (Decoder) Err

func (decoder Decoder) Err() error

func (Decoder) Key

func (decoder Decoder) Key() (int, int, error)

Key returns the "begin index" and "end index" for the current dotquote key.

func (Decoder) KeyBytes

func (decoder Decoder) KeyBytes() ([]byte, error)

KeyBytes returns a []byte to the current dotquote key.

Note that this is a slice on the []byte originally given to this decoder, in its "Bytes" field.

It is NOT a copy.

func (Decoder) KeyString

func (decoder Decoder) KeyString() (string, error)

KeyString returns the current dotquote key, as a string.

func (Decoder) MustKey

func (decoder Decoder) MustKey() (int, int)

MustKey is like the Key method, expect it panic()s on an error.

func (Decoder) MustKeyBytes

func (decoder Decoder) MustKeyBytes() []byte

MustKeyBytes is like the KeyBytes method, expect it panic()s on an error.

func (Decoder) MustKeyString

func (decoder Decoder) MustKeyString() string

MustKeyString is like the KeyString method, expect it panic()s on an error.

func (*Decoder) Next

func (decoder *Decoder) Next() bool

func (*Decoder) Values

func (decoder *Decoder) Values() *DecoderValues

type DecoderValues

type DecoderValues struct {
	// contains filtered or unexported fields
}

func (DecoderValues) Err

func (v DecoderValues) Err() error

func (DecoderValues) MustValue

func (v DecoderValues) MustValue() (int, int)

MustValue is like Value, expect it panic()s on an error.

func (DecoderValues) MustValueBytes

func (v DecoderValues) MustValueBytes() []byte

MustValueBytes is like ValueBytes, expect it panic()s on an error.

func (DecoderValues) MustValueString

func (v DecoderValues) MustValueString() string

MustValueString is like ValueString, expect it panic()s on an error.

func (*DecoderValues) Next

func (v *DecoderValues) Next() bool

func (DecoderValues) UnquotedValueString

func (v DecoderValues) UnquotedValueString() (string, error)

func (DecoderValues) Value

func (v DecoderValues) Value() (int, int, error)

func (DecoderValues) ValueBytes

func (v DecoderValues) ValueBytes() ([]byte, error)

func (DecoderValues) ValueString

func (v DecoderValues) ValueString() (string, error)

type Logger

type Logger interface {
	Debug(...interface{})
	Debugf(string, ...interface{})

	Trace(...interface{})
	Tracef(string, ...interface{})
}

Directories

Path Synopsis
Package dotquotedetect is a low level library for detecting where keys and values are in dotquote data in a []byte.
Package dotquotedetect is a low level library for detecting where keys and values are in dotquote data in a []byte.

Jump to

Keyboard shortcuts

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