ltsvdoc

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2018 License: MIT Imports: 7 Imported by: 0

README

koron-go/ltsvdoc

GoDoc CircleCI Go Report Card

LTSV document based encoder/decoder.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegister = NewRegistry()

DefaultRegister is a Registry which used as default in this package.

Functions

func EncodeAll

func EncodeAll(vals ...Marshaler) ([]byte, error)

EncodeAll encodes all marshalers as LTSV to []byte.

func Register

func Register(name string, doc Doc)

Register registers a type as LTSV marshal/unmarshal-able.

Types

type Decoder

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

Decoder provides LTSV doc decoding.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates a new decoder.

func NewDecoderWithRegistry

func NewDecoderWithRegistry(reg *Registry, r io.Reader) *Decoder

NewDecoderWithRegistry creates a new decoder with Registry.

func (Decoder) Decode

func (d Decoder) Decode() (Unmarshaler, error)

Decode decodes a document.

type Doc

type Doc interface {
	Marshaler
	Unmarshaler
}

Doc defines required functions for LTSV marshal/unmarshal-able type.

type Encoder

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

Encoder encodes Marshalers as LTSV lines.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder cerates a new Encoder using io.Writer.

func NewEncoderWithRegistry

func NewEncoderWithRegistry(reg *Registry, w io.Writer) *Encoder

NewEncoderWithRegistry creates a new Encoder with Registry.

func (*Encoder) Encode

func (e *Encoder) Encode(v Marshaler) error

Encode encodes a Marshaler

type LabelValue

type LabelValue struct {
	Label string
	Value interface{}
}

LabelValue is a pair of label and value.

func NewLabelValue

func NewLabelValue(label string, value interface{}) *LabelValue

NewLabelValue creates a labeled value.

func (LabelValue) ValueString

func (v LabelValue) ValueString() string

ValueString get a string representation of value.

type Marshaler

type Marshaler interface {
	MarshalLTSV() (Values, error)
}

Marshaler defines LTSV row marshaler

type Reader

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

Reader reads LTSV values.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader creates a new LTSV reader.

func (*Reader) Read

func (r *Reader) Read() (Values, error)

Read read a LTSV value.

type Registry

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

Registry is a regisry of LTSV marshal/unmarshal-able types.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new Registry.

func (*Registry) Add

func (reg *Registry) Add(name string, doc Doc) error

Add adds a type as LTSV marshal/unmarshal-able.

func (*Registry) DecodeAll

func (reg *Registry) DecodeAll(r io.Reader) ([]Unmarshaler, error)

DecodeAll decodes all unmarshalers from io.Reader.

func (*Registry) EncodeAll

func (reg *Registry) EncodeAll(w io.Writer, vals ...Marshaler) error

EncodeAll encodes all marshalers as LTSV to io.Writer.

type Unmarshaler

type Unmarshaler interface {
	UnmarshalLTSV(Values) error
}

Unmarshaler defines LTSV marshaler

func DecodeAll

func DecodeAll(b []byte) ([]Unmarshaler, error)

DecodeAll decodes all unmarshalers from []byte.

type Values

type Values []*LabelValue

Values is an array of LabelValue

func NewValues

func NewValues(args ...interface{}) Values

NewValues creates a Values with capacity.

func (*Values) Add

func (vals *Values) Add(label string, value interface{}) *Values

Add addes a value to Values.

func (Values) WriteTo

func (vals Values) WriteTo(w io.Writer) (int64, error)

WriteTo writes LTSV string to io.Writer

Jump to

Keyboard shortcuts

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