package msgio
import "github.com/libp2p/go-msgio"
Index ¶
- Variables
- func LimitedReader(r io.Reader) (io.Reader, error)
- func ReadLen(r io.Reader, buf []byte) (int, error)
- func WriteLen(w io.Writer, l int) error
- type LimitedWriter
- func NewLimitedWriter(w io.Writer) *LimitedWriter
- func (w *LimitedWriter) Flush() error
- func (w *LimitedWriter) Write(buf []byte) (n int, err error)
- type ReadCloser
- func NewReader(r io.Reader) ReadCloser
- func NewReaderSize(r io.Reader, maxMessageSize int) ReadCloser
- func NewReaderSizeWithPool(r io.Reader, maxMessageSize int, p *pool.BufferPool) ReadCloser
- func NewReaderWithPool(r io.Reader, p *pool.BufferPool) ReadCloser
- func NewVarintReader(r io.Reader) ReadCloser
- func NewVarintReaderSize(r io.Reader, maxMessageSize int) ReadCloser
- func NewVarintReaderSizeWithPool(r io.Reader, maxMessageSize int, p *pool.BufferPool) ReadCloser
- func NewVarintReaderWithPool(r io.Reader, p *pool.BufferPool) ReadCloser
- type ReadWriteCloser
- func Combine(w Writer, r Reader) ReadWriteCloser
- func NewReadWriter(rw io.ReadWriter) ReadWriteCloser
- type ReadWriter
- type Reader
- type WriteCloser
- func NewVarintWriter(w io.Writer) WriteCloser
- func NewVarintWriterWithPool(w io.Writer, p *pool.BufferPool) WriteCloser
- func NewWriter(w io.Writer) WriteCloser
- func NewWriterWithPool(w io.Writer, p *pool.BufferPool) WriteCloser
- type Writer
Variables ¶
ErrMsgTooLarge is returned when the message length is exessive
NBO is NetworkByteOrder
Functions ¶
func LimitedReader ¶
LimitedReader wraps an io.Reader with a msgio framed reader. The LimitedReader will return a reader which will io.EOF when the msg length is done.
func ReadLen ¶
ReadLen reads a length from the given reader. if buf is non-nil, it reuses the buffer. Ex:
l, err := ReadLen(r, nil) _, err := ReadLen(r, buf)
func WriteLen ¶
WriteLen writes a length to the given writer.
Types ¶
type LimitedWriter ¶
func NewLimitedWriter ¶
func NewLimitedWriter(w io.Writer) *LimitedWriter
LimitedWriter wraps an io.Writer with a msgio framed writer. It is the inverse of LimitedReader: it will buffer all writes until "Flush" is called. When Flush is called, it will write the size of the buffer first, flush the buffer, reset the buffer, and begin accept more incoming writes.
func (*LimitedWriter) Flush ¶
func (w *LimitedWriter) Flush() error
func (*LimitedWriter) Write ¶
func (w *LimitedWriter) Write(buf []byte) (n int, err error)
type ReadCloser ¶
ReadCloser combines a Reader and Closer.
func NewReader ¶
func NewReader(r io.Reader) ReadCloser
NewReader wraps an io.Reader with a msgio framed reader. The msgio.Reader will read whole messages at a time (using the length). Assumes an equivalent writer on the other side.
func NewReaderSize ¶
func NewReaderSize(r io.Reader, maxMessageSize int) ReadCloser
NewReaderSize is equivalent to NewReader but allows one to specify a max message size.
func NewReaderSizeWithPool ¶
func NewReaderSizeWithPool(r io.Reader, maxMessageSize int, p *pool.BufferPool) ReadCloser
NewReaderWithPool is the same as NewReader but allows one to specify a buffer pool and a max message size.
func NewReaderWithPool ¶
func NewReaderWithPool(r io.Reader, p *pool.BufferPool) ReadCloser
NewReaderWithPool is the same as NewReader but allows one to specify a buffer pool.
func NewVarintReader ¶
func NewVarintReader(r io.Reader) ReadCloser
NewVarintReader wraps an io.Reader with a varint msgio framed reader. The msgio.Reader will read whole messages at a time (using the length). Varints read according to https://golang.org/pkg/encoding/binary/#ReadUvarint Assumes an equivalent writer on the other side.
func NewVarintReaderSize ¶
func NewVarintReaderSize(r io.Reader, maxMessageSize int) ReadCloser
NewVarintReaderSize is equivalent to NewVarintReader but allows one to specify a max message size.
func NewVarintReaderSizeWithPool ¶
func NewVarintReaderSizeWithPool(r io.Reader, maxMessageSize int, p *pool.BufferPool) ReadCloser
NewVarintReaderWithPool is the same as NewVarintReader but allows one to specify a buffer pool and a max message size.
func NewVarintReaderWithPool ¶
func NewVarintReaderWithPool(r io.Reader, p *pool.BufferPool) ReadCloser
NewVarintReaderWithPool is the same as NewVarintReader but allows one to specify a buffer pool.
type ReadWriteCloser ¶
ReadWriteCloser combines a Reader, a Writer, and Closer.
func Combine ¶
func Combine(w Writer, r Reader) ReadWriteCloser
Combine wraps a pair of msgio.Writer and msgio.Reader with a msgio.ReadWriter.
func NewReadWriter ¶
func NewReadWriter(rw io.ReadWriter) ReadWriteCloser
NewReadWriter wraps an io.ReadWriter with a msgio.ReadWriter. Writing and Reading will be appropriately framed.
type ReadWriter ¶
ReadWriter combines a Reader and Writer.
type Reader ¶
type Reader interface { // Read reads the next message from the Reader. // The client must pass a buffer large enough, or io.ErrShortBuffer will be // returned. Read([]byte) (int, error) // ReadMsg reads the next message from the Reader. // Uses a pool.BufferPool internally to reuse buffers. User may call // ReleaseMsg(msg) to signal a buffer can be reused. ReadMsg() ([]byte, error) // ReleaseMsg signals a buffer can be reused. ReleaseMsg([]byte) // NextMsgLen returns the length of the next (peeked) message. Does // not destroy the message or have other adverse effects NextMsgLen() (int, error) }
Reader is the msgio Reader interface. It reads len-framed messages.
type WriteCloser ¶
WriteCloser is a Writer + Closer interface. Like in `golang/pkg/io`
func NewVarintWriter ¶
func NewVarintWriter(w io.Writer) WriteCloser
NewVarintWriter wraps an io.Writer with a varint msgio framed writer. The msgio.Writer will write the length prefix of every message written as a varint, using https://golang.org/pkg/encoding/binary/#PutUvarint
func NewVarintWriterWithPool ¶
func NewVarintWriterWithPool(w io.Writer, p *pool.BufferPool) WriteCloser
func NewWriter ¶
func NewWriter(w io.Writer) WriteCloser
NewWriter wraps an io.Writer with a msgio framed writer. The msgio.Writer will write the length prefix of every message written.
func NewWriterWithPool ¶
func NewWriterWithPool(w io.Writer, p *pool.BufferPool) WriteCloser
NewWriterWithPool is identical to NewWriter but allows the user to pass a custom buffer pool.
type Writer ¶
type Writer interface { // Write writes passed in buffer as a single message. Write([]byte) (int, error) // WriteMsg writes the msg in the passed in buffer. WriteMsg([]byte) error }
Writer is the msgio Writer interface. It writes len-framed messages.
Source Files ¶
limit.go msgio.go num.go varint.go
Directories ¶
Path | Synopsis |
---|---|
msgio | |
pbio | Package pbio reads and writes varint-prefix protobufs, using Google's Protobuf package. |
pbio/pb | |
protoio | Adapted from gogo/protobuf to use multiformats/go-varint for efficient, interoperable length-prefixing. |
- Version
- v0.3.0 (latest)
- Published
- Jan 12, 2023
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 1 month ago –
Tools for package owners.