bit

package
v0.0.0-...-972597a Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Unlicense Imports: 2 Imported by: 6

Documentation

Overview

Package bit implements bit level encoding wrappers for io.Reader / io.Writer All operations are Little Endian where applicable

Note that Write/Read operations do not return error for convenience, you must check bit.Reader.Error() or bit.Writer.Error() manually

Index

Constants

View Source
const NotFound = 0xFF

Variables

This section is empty.

Functions

func Count

func Count(x uint64) int

func Read

func Read(r io.Reader, vs ...interface{}) error

func Reverse

func Reverse(x uint64, width uint) (rx uint64)

func ScanLeft

func ScanLeft(x uint64) uint

ScanLeft scans from the lowest to the highest bit if x == 0 it will return NotFound

func ScanRight

func ScanRight(x uint64) uint

ScanRight scans from the highest to the lowest bit if x == 0 it will return NotFound

func Write

func Write(w io.Writer, vs ...interface{}) error

func ZDecode

func ZDecode(ux uint64) int64

ZDecode is the inverse operation of ZEncode ZDecode(ZEncode(x)) == x

func ZEncode

func ZEncode(x int64) uint64

ZEncode implements zig-zag encoding The sign will be encoded as the least significant bit in the result ZEncode(x) < abs(x)*2

Types

type Reader

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

func NewReader

func NewReader(r io.Reader) *Reader

func (*Reader) Align

func (r *Reader) Align()

Align aligns the reader to the next byte so that the next ReadBits will start reading a new byte from the underlying reader

func (*Reader) Error

func (r *Reader) Error() error

func (*Reader) ReadBit

func (r *Reader) ReadBit() int

ReadBit reads a single bit from the underlying reader

func (*Reader) ReadBits

func (r *Reader) ReadBits(width uint) uint64

ReadBits reads width bits from the underlying reader

func (*Reader) ReadBool

func (r *Reader) ReadBool() bool

ReadBool reads a single bool from the underlying reader

func (*Reader) ReadByte

func (r *Reader) ReadByte() byte

ReadByte reads a single bit from the underlying reader

type Writer

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

func NewWriter

func NewWriter(w io.Writer) *Writer

func (*Writer) Align

func (w *Writer) Align()

Align aligns the writer to the next byte

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) Error

func (w *Writer) Error() error

func (*Writer) WriteBit

func (w *Writer) WriteBit(x int)

WriteBit writes the lowest bit in x to the underlying writer

func (*Writer) WriteBits

func (w *Writer) WriteBits(x uint64, width uint)

WriteBits writes width lowest bits to the underlying writer

func (*Writer) WriteBool

func (w *Writer) WriteBool(x bool)

WriteBool writes a bool the underlying writer depending on x

func (*Writer) WriteByte

func (w *Writer) WriteByte(v byte)

WriteByte writes a byte to the underlying writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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