bitio

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Implements LSb-First reader and writer for reading/writing arbitrary bit width integers from/to normal go byte streams. An example use case is Vorbis coding. Note that this implementation is completely unoptimized. The Writer needs to cache the byte it is about write, so FlushByte() must be called to ensure the stream is re-aligned to 8bits and all data is written.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	io.Reader
	// contains filtered or unexported fields
}

Reads individual bits. Bit order: LSb-First

func NewReader

func NewReader(r io.Reader) *Reader

func (*Reader) BitsRead

func (r *Reader) BitsRead() int

func (*Reader) IsAligned

func (r *Reader) IsAligned() bool

Returns true if the reader is currently 8-bit aligned (and thus is in sync with the underlying reader)

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

n may be inaccurate if reading fails within byte boundaries.

func (*Reader) ReadBit

func (r *Reader) ReadBit() (bool, error)

func (*Reader) ReadBits

func (r *Reader) ReadBits(nb uint8) (val uint64, n int, err error)

type Writer

type Writer struct {
	io.Writer
	// contains filtered or unexported fields
}

Writes individual bits. Bit order: LSb-First

func NewWriter

func NewWriter(w io.Writer) *Writer

func (*Writer) BitsWritten

func (w *Writer) BitsWritten() int

func (*Writer) FlushByte

func (w *Writer) FlushByte() error

func (*Writer) IsAligned

func (w *Writer) IsAligned() bool

Returns true if the writer is currently 8-bit aligned (and thus flushing will do nothing).

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

n may be inaccurate if writing fails within byte boundaries.

func (*Writer) WriteBit

func (w *Writer) WriteBit(b bool) error

func (*Writer) WriteBits

func (w *Writer) WriteBits(b uint64, nb uint8) (n int, err error)

Writes nb bits of b in LSb-First order. Returns number of bits successfully written.

func (*Writer) WriteBitsMany

func (w *Writer) WriteBitsMany(args ...uint64) (n int, err error)

Arg format is: value, nBits, value, nBits... Returns number of bits successfully written.

Jump to

Keyboard shortcuts

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