bitstream

package module
Version: v0.0.0-...-3522498 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2018 License: MIT Imports: 1 Imported by: 0

README

bitstream: read and write bits from io.Reader and io.Writer streams

Full package documentation available at: http://godoc.org/github.com/dgryski/go-bitstream

Documentation

Overview

Package bitstream is a simple wrapper around a io.Reader and io.Writer to provide bit-level access to the stream.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bit

type Bit bool

A Bit is a zero or a one

const (
	// Zero is our exported type for '0' bits
	Zero Bit = false
	// One is our exported type for '1' bits
	One Bit = true
)

type BitReader

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

A BitReader reads bits from an io.Reader

func NewReader

func NewReader(r io.Reader) *BitReader

NewReader returns a BitReader that returns a single bit at a time from 'r'

func (*BitReader) ReadBit

func (b *BitReader) ReadBit() (Bit, error)

ReadBit returns the next bit from the stream, reading a new byte from the underlying reader if required.

func (*BitReader) ReadBits

func (b *BitReader) ReadBits(nbits int) (uint64, error)

ReadBits reads nbits from the stream

func (*BitReader) ReadByte

func (b *BitReader) ReadByte() (byte, error)

ReadByte reads a single byte from the stream, regardless of alignment

func (*BitReader) Reset

func (b *BitReader) Reset(r io.Reader)

Reset replaces the underlying io.Reader with the provided reader and resets all interal state to its zero value, allowing for reuse of the BitReader without additional allocations

type BitWriter

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

A BitWriter writes bits to an io.Writer

func NewWriter

func NewWriter(w io.Writer) *BitWriter

NewWriter returns a BitWriter that buffers bits and write the resulting bytes to 'w'

func (*BitWriter) Flush

func (b *BitWriter) Flush(bit Bit) error

Flush empties the currently in-process byte by filling it with 'bit'.

func (*BitWriter) Pending

func (b *BitWriter) Pending() (byt byte, vals uint8)

func (*BitWriter) Reset

func (b *BitWriter) Reset(w io.Writer)

Reset replaces the underlying io.Writer with the provided writer and resets all internal state to its initial value allowing for reuse of the BitWriter without additional allocations

func (*BitWriter) Resume

func (b *BitWriter) Resume(data byte, count uint8)

func (*BitWriter) WriteBit

func (b *BitWriter) WriteBit(bit Bit) error

WriteBit writes a single bit to the stream, writing a new byte to 'w' if required.

func (*BitWriter) WriteBits

func (b *BitWriter) WriteBits(u uint64, nbits int) error

WriteBits writes the nbits least significant bits of u, most-significant-bit first.

func (*BitWriter) WriteByte

func (b *BitWriter) WriteByte(byt byte) error

WriteByte writes a single byte to the stream, regardless of alignment

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL