Categorygithub.com/Rorical/go-msgio
modulepackage
0.1.0
Repository: https://github.com/rorical/go-msgio.git
Documentation: pkg.go.dev

# README

go-msgio - Message IO

codecov Travis CI Discourse posts

This is a simple package that helps read and write length-delimited slices. It's helpful for building wire protocols.

Usage

Reading

import "github.com/libp2p/go-msgio"
rdr := ... // some reader from a wire
mrdr := msgio.NewReader(rdr)

for {
  msg, err := mrdr.ReadMsg()
  if err != nil {
    return err
  }

  doSomething(msg)
}

Writing

import "github.com/libp2p/go-msgio"
wtr := genReader()
mwtr := msgio.NewWriter(wtr)

for {
  msg := genMessage()
  err := mwtr.WriteMsg(msg)
  if err != nil {
    return err
  }
}

Duplex

import "github.com/libp2p/go-msgio"
rw := genReadWriter()
mrw := msgio.NewReadWriter(rw)

for {
  msg, err := mrdr.ReadMsg()
  if err != nil {
    return err
  }

  // echo it back :)
  err = mwtr.WriteMsg(msg)
  if err != nil {
    return err
  }
}

Channels

import "github.com/libp2p/go-msgio"
rw := genReadWriter()
rch := msgio.NewReadChannel(rw)
wch := msgio.NewWriteChannel(rw)

for {
  msg, err := <-rch
  if err != nil {
    return err
  }

  // echo it back :)
  wch<- rw
}

The last gx published version of this module was: 0.0.6: QmcxL9MDzSU5Mj1GcWZD8CXkAFuJXjdbjotZ93o371bKSf

# Packages

No description provided by the author
Adapted from gogo/protobuf to use multiformats/go-varint for efficient, interoperable length-prefixing.

# Functions

Combine wraps a pair of msgio.Writer and msgio.Reader with a msgio.ReadWriter.
LimitedReader wraps an io.Reader with a msgio framed reader.
LimitedWriter wraps an io.Writer with a msgio framed writer.
NewReader wraps an io.Reader with a msgio framed reader.
NewReaderSize is equivalent to NewReader but allows one to specify a max message size.
NewReaderWithPool is the same as NewReader but allows one to specify a buffer pool and a max message size.
NewReaderWithPool is the same as NewReader but allows one to specify a buffer pool.
NewReadWriter wraps an io.ReadWriter with a msgio.ReadWriter.
NewVarintReader wraps an io.Reader with a varint msgio framed reader.
NewVarintReaderSize is equivalent to NewVarintReader but allows one to specify a max message size.
NewVarintReaderWithPool is the same as NewVarintReader but allows one to specify a buffer pool and a max message size.
NewVarintReaderWithPool is the same as NewVarintReader but allows one to specify a buffer pool.
NewVarintWriter wraps an io.Writer with a varint msgio framed writer.
No description provided by the author
NewWriter wraps an io.Writer with a msgio framed writer.
NewWriterWithPool is identical to NewWriter but allows the user to pass a custom buffer pool.
ReadLen reads a length from the given reader.
WriteLen writes a length to the given writer.

# Variables

ErrMsgTooLarge is returned when the message length is exessive.
NBO is NetworkByteOrder.

# Structs

No description provided by the author

# Interfaces

ReadCloser combines a Reader and Closer.
Reader is the msgio Reader interface.
ReadWriteCloser combines a Reader, a Writer, and Closer.
ReadWriter combines a Reader and Writer.
WriteCloser is a Writer + Closer interface.
Writer is the msgio Writer interface.