gob

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gob provides support for reading and writing a stream of gob-encoded obejcts.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingType = errors.New("missing type")
	ErrInvalidType = errors.New("invalid type, expecting map or struct")
)

Functions

func Marshal

func Marshal(obj interface{}, fit bool) ([]byte, error)

Marshal formats an object into a slice of gob-encoded bytes.

func Read

func Read(input *ReadInput) (interface{}, error)

Read reads the sequence of gob items from the input reader of the type given.

func RegisterTypes

func RegisterTypes()

RegisterTypes registers some default types that are not registered by default by the standard library gob package.

func Write

func Write(input *WriteInput) error

Write writes the given object(s) as gob-encoded items. As gob is a stream encoding, if provded an object of array or slice, then each contained element is written as its own item. If not provided an array or slice, then the provided object is encoded as is as a gob item.

Types

type Encoder

type Encoder struct {
	*gob.Encoder
}

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

Encoder returns a new gob encoder given the underlying writer.

type Iterator

type Iterator struct {
	Type    reflect.Type    // the type to unmarshal for each item
	Decoder *stdgob.Decoder // the scanner that splits the underlying stream of bytes
	Limit   int             // Limit the number of objects to read and return from the underlying stream.
	Count   int             // The current count of the number of objects read.
}

Iterator iterates trough a stream of bytes returning a new object on each call of Next() until it reaches the end and returns io.EOF.

func NewIterator

func NewIterator(input *NewIteratorInput) *Iterator

NewIterator returns a new gob iterator base on the given input.

func (*Iterator) Next

func (it *Iterator) Next() (interface{}, error)

Next reads from the underlying reader and returns the next object and error, if any. If a blank line is found and SkipBlanks is false, then returns (nil, nil). If a commented line is found and SkipComments is false, then returns (nil, nil). When the input stream is exhausted, returns (nil, io.EOF).

type NewIteratorInput

type NewIteratorInput struct {
	Reader io.Reader
	Type   reflect.Type // the type to unmarshal for each line
	Limit  int          // Limit the number of objects to read and return from the underlying stream.
}

Input for NewIterator function.

type ReadInput

type ReadInput struct {
	Type   reflect.Type // the output type
	Reader io.Reader    // the underlying reader
	Limit  int
}

ReadInput provides the input parameters for the Read function.

type WriteInput

type WriteInput struct {
	Writer io.Writer   // the underlying writer
	Object interface{} // the object to write
	Limit  int
	Fit    bool
}

WriteInput provides the input for the Write function.

type Writer

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

Writer formats and writes objects to the underlying writer as gob-encoded items.

func NewWriter

func NewWriter(w io.Writer, fit bool) *Writer

NewWriter returns a writer for formating and writing objets to the underlying writer as gob-encoded items.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the underlying writer, if it has a Close method.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush flushes the underlying writer, if it has a Flush method. This writer itself does no buffering.

func (*Writer) WriteObject

func (w *Writer) WriteObject(obj interface{}) error

WriteObject formats and writes a single object to the underlying writer as a gob-encoded item.

func (*Writer) WriteObjects

func (w *Writer) WriteObjects(objects interface{}) error

WriteObjects formats and writes the given objects to the underlying writer.

Jump to

Keyboard shortcuts

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