ltsvdoc

package module
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 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) RawValueString added in v0.9.3

func (v LabelValue) RawValueString() string

RawValueString return value in string form without any quotes.

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 Proxy added in v0.9.1

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

Proxy represents a proxy for Values.

func NewProxy added in v0.9.1

func NewProxy(vals Values) *Proxy

NewProxy creates a new Proxy for Values.

func (*Proxy) Error added in v0.9.1

func (p *Proxy) Error() error

Error returns a first error occurrence.

func (*Proxy) Get added in v0.9.1

func (p *Proxy) Get(label string) *ProxyValue

Get returns a proxy for a value at first.

func (*Proxy) Has added in v0.9.1

func (p *Proxy) Has(label string) bool

Has checks Values has a label or not.

func (*Proxy) Opt added in v0.9.1

func (p *Proxy) Opt(label string) *ProxyValue

Opt return a proxy for a value without error propagation.

type ProxyValue added in v0.9.1

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

Proxy represents a proxy for LabelValue.

func (*ProxyValue) Bool added in v0.9.2

func (pv *ProxyValue) Bool() bool

Bool returns a bool value

func (*ProxyValue) Error added in v0.9.1

func (pv *ProxyValue) Error() error

Error gets a last occurred error.

func (*ProxyValue) Float64 added in v0.9.2

func (pv *ProxyValue) Float64() float64

Float64 returns a float64 value.

func (*ProxyValue) Int32 added in v0.9.1

func (pv *ProxyValue) Int32() int32

Int32 returns a int32 value.

func (*ProxyValue) Int64 added in v0.9.1

func (pv *ProxyValue) Int64() int64

Int64 returns a int64 value.

func (*ProxyValue) String added in v0.9.1

func (pv *ProxyValue) String() string

String returns a string value.

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) Append added in v0.9.1

func (vals *Values) Append(args ...interface{}) *Values

Append adds multiple values 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