pack

package
v0.0.0-...-8b31643 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: ISC Imports: 6 Imported by: 0

Documentation

Overview

Package pack is the message packing scheme for venti, and some convenience functions for reading/writing venti packets.

See venti(7) from Plan 9 or plan9port.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func String

func String(b []byte, s string) int

String writes the string into the []byte, returning the number of bytes used.

func Uint16

func Uint16(b []byte, v uint16) int

Uint16 writes the uint16 into the []byte, returning the number of bytes used.

func Uint32

func Uint32(b []byte, v uint32) int

Uint32 writes the uint32 into the []byte, returning the number of bytes used.

func Uint64

func Uint64(b []byte, v uint64) int

Uint64 writes the uint64 into the []byte, returning the number of bytes used.

func UnString

func UnString(b []byte) (int, string)

UnString unpacks a string from the []byte, returning the number of bytes used and the string.

func UnUint16

func UnUint16(b []byte) (int, uint16)

UnUint16 unpacks a string from the []byte, returning the number of bytes used and the uint16.

func UnUint32

func UnUint32(b []byte) (int, uint32)

UnUint32 unpacks a string from the []byte, returning the number of bytes used and the uint32.

func UnUint64

func UnUint64(b []byte) (int, uint64)

UnUint64 unpacks a string from the []byte, returning the number of bytes used and the uint64.

func UnVar

func UnVar(b []byte) (int, []byte)

UnVar unpacks a []byte from the []byte b. The returned slice shares the backing array, and the int is the number of bytes used.

func Var

func Var(b []byte, v []byte) int

Var copies the []byte v into []byte b, returning the number of bytes used.

Types

type Chunker

type Chunker struct {
	Chatty bool
	// contains filtered or unexported fields
}

Chunker yeilds writers that emit venti-format packets.

We only emit venti v04 compatable packets.

func Chunk

func Chunk(w io.Writer) *Chunker

Chunk returns a Chunker that writes to 'w'.

func (*Chunker) New

func (w *Chunker) New() io.WriteCloser

New returns a io.WriteCloser that buffers writes and frames and flushes data when closed.

type Dechunker

type Dechunker struct {
	sync.Mutex

	Chatty bool
	// contains filtered or unexported fields
}

Dechunker reads venti-format packets. It strips the leading length and inserts io.EOFs after each.

We only support venti v04 compatable packets.

func Dechunk

func Dechunk(r io.Reader) *Dechunker

Dechunk return a Dechunker reading from 'r'.

func (*Dechunker) Line

func (d *Dechunker) Line() (string, error)

Line reads until the next '\n'. Used for the initial version exchange.

func (*Dechunker) Read

func (d *Dechunker) Read(b []byte) (int, error)

Read reads until the end of the message.

A Read call after an io.EOF is returned will read the next packet.

Jump to

Keyboard shortcuts

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