codec

package
v0.0.0-...-18ff271 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MessageRef indicates this is a Ref message
	MessageRef = 1
	// MessageDef indicates this is a Def message
	MessageDef = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DelimitedReader

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

DelimitedReader consumes length-delimited records from a byte source.

Usage:

rd := delimited.NewReader(r)
for {
  rec, err := rd.Next()
  if err == io.EOF {
    break
  } else if err != nil {
    log.Fatal(err)
  }
  doStuffWith(rec)
}

func NewDelimitedReader

func NewDelimitedReader(r io.Reader) *DelimitedReader

NewDelimitedReader constructs a new delimited Reader for the records in r.

func (*DelimitedReader) Next

func (r *DelimitedReader) Next() ([]byte, error)

Next returns the next length-delimited record from the input, or io.EOF if there are no more records available. Returns io.ErrUnexpectedEOF if a short record is found, with a length of n but fewer than n bytes of data. Because there is no resynchronization mechanism, it is generally not possible to recover from a short record in this format.

The slice returned is valid only until a subsequent call to Next.

func (*DelimitedReader) NextProto

func (r *DelimitedReader) NextProto(pb proto.Message) error

NextProto consumes the next available record by calling r.Next, and decodes it into pb with proto.Unmarshal.

type DelimitedWriter

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

A DelimitedWriter outputs delimited records to an io.Writer.

Basic usage:

wr := delimited.NewWriter(w)
for record := range records {
   if err := wr.Put(record); err != nil {
     log.Fatal(err)
   }
}

func NewDelimitedWriter

func NewDelimitedWriter(w io.Writer) *DelimitedWriter

NewDelimitedWriter constructs a new delimited Writer that writes records to w.

func (DelimitedWriter) Put

func (w DelimitedWriter) Put(record []byte) error

Put writes the specified record to the writer. It equivalent to WriteRecord, but discards the number of bytes written.

func (DelimitedWriter) PutProto

func (w DelimitedWriter) PutProto(msg proto.Message) error

PutProto encodes and writes the specified proto.Message to the writer.

func (DelimitedWriter) WriteRecord

func (w DelimitedWriter) WriteRecord(record []byte) (int, error)

WriteRecord writes the specified record to the underlying writer, returning the total number of bytes written including the length tag.

type GobReader

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

GobReader allows us to read gob encoded streams

func (*GobReader) Read

func (r *GobReader) Read() (Message, error)

Read returns the next message available in the input stream

type GobWriter

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

GobWriter implements SegmentWriter. It writes segments that are gob encoded to a given output stream

func (*GobWriter) Write

func (g *GobWriter) Write(msg *Message) error

Write emits the message to the output stream

type Message

type Message struct {
	Type     uint16
	RefID    uint64
	DefID    uint64
	DefBytes []byte
}

Message is the message that we write to the output stream

type Reader

type Reader interface {
	Read() (Message, error)
}

Reader interface allows callers to read a stream of protocol messages

func NewGobReader

func NewGobReader(input io.Reader) Reader

NewGobReader returns a codec.Reader capable of reading golang/gob encoded messages from input streams

type Writer

type Writer interface {
	Write(*Message) error
}

Writer interface allows callers to write the protocol messages to a sink

func NewGobWriter

func NewGobWriter(output io.Writer) Writer

NewGobWriter returns a codec.writer capable of emitting golang/gob encoded messages to the specified output

Jump to

Keyboard shortcuts

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