Skip to content
simple package to r/w length-delimited slices.
Go
Branch: master
Clone or download
Pull request Compare This branch is 43 commits ahead of jbenet:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
msgio fix repo Nov 19, 2017
.gxignore
.travis.yml farewell gx; thanks for serving us well. Apr 11, 2019
LICENSE
README.md
chan.go even fewer allocations Jun 6, 2019
chan_test.go
codecov.yml Update Travis CI to use standard test script. Dec 5, 2017
fuzz.go
fuzz_test.go
go.mod
go.sum Add gomod, update travis Feb 27, 2019
limit.go
limit_test.go test: expand tests for msgio readers and writers Jan 16, 2019
msgio.go
msgio_test.go Add gomod, update travis Feb 27, 2019
num.go
varint.go make the maximum message size configurable Jun 14, 2019
varint_test.go

README.md

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

You can’t perform that action at this time.