format

package
v0.0.0-...-d0f7b5f Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrNoHeader means that the names of columns need
	//to be specified by the input but were not.
	ErrNoHeader = errors.New("column names cannot be derived")

	//ErrFrameRequired means the format requires a table
	//name to choose the appropriate data table to decode.
	ErrFrameRequired = errors.New("frame name is required")
)

Functions

func IsFormatErr

func IsFormatErr(e error) bool

IsFormatErr returns whether e is an error in the format.

func NewDimErr

func NewDimErr(ctx string, expected, got int) error

NewDimErr creates a new dimension error when the input, described by ctx, expected n column but got m.

func Wrap

func Wrap(ctx string, err error) error

Wrap an error as a format error.

Types

type Decoder

type Decoder interface {
	//Name reports the name of the format being decoded.
	//It may be called at any time.
	Name() string

	//Init decoder to read from r.
	Init(r device.Reader) error

	//ReadHeader prepares the Decoder to read records from the current device.
	//
	//If ReadHeader is called on a format that contains multiple data frames
	//and no frame is provided, ReadHeader must return ErrFrameRequired.
	//
	//If ReadHeader is called on a format, or instance, that does not contain a header,
	//and no header is provided, ReadHeader must return ErrNoHeader.
	//
	//If a nonempty header is passed to ReadHeader, it must be returned.
	//
	//ReadHeader must never return data and an error.
	//
	//Clients must not assume it is safe to modify the returned slice.
	ReadHeader(frame string, header []string) ([]string, error)

	//Skip rows. Used by OFFSET.
	Skip(rows int) error

	//ReadRow will be called until it returns io.EOF
	//
	//ReadRow must never return data and an error.
	//
	//Clients must not assume it is safe to modify the returned slice.
	ReadRow() ([]*string, error)

	//Reset is called after an import.
	//
	//The next call will either be to Init or Close.
	Reset() error

	//Close is called when the Decoder will never be used again.
	Close() error
}

Decoder specifies the protocol for a format to be imported into a database.

A Decoder will be called with Init to set the input device.

For each table,

ReadHeader will be called once.
Skip will be called 0 or more times.
ReadRow will be called 0 or more times.
Reset will be called once.

When a Decoder is retired Close will be called once.

It may be re-initialized later with a different input device.

type Encoder

type Encoder interface {
	//Name reports the name of the format being encoded.
	//It may be called at any time.
	Name() string

	//Init encoder to write to w.
	Init(w device.Writer) error

	//WriteHeader may choose to not write the header, depending on format.
	//
	//If the format requires the name of a data frame to write and none is provided,
	//WriteHeader must return ErrFrameRequired.
	WriteHeader(frame string, header []string) error
	WriteRow([]*string) error
	Reset() error
	Close() error
}

Encoder encodes an SQLite table as text. For each table,

WriteHeader will be called once.
WriteRow will be called 0 or more times.
Reset will be called once.

When an Encoder is to be retired Close will be called once.

Directories

Path Synopsis
Package rawfmt defines encoding and decoding of the raw format.
Package rawfmt defines encoding and decoding of the raw format.

Jump to

Keyboard shortcuts

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