bits

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bits provides an MSB-first bit reader matching the bit-position and overrun semantics of minimp3's bs_t/get_bits (see minimp3.h, CC0-1.0), which every decode unit in this package reads its bitstream through.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

Reader is an MSB-first bit reader. Position and limit are tracked in bits, not bytes, mirroring upstream bs_t.

func NewReader

func NewReader(buf []byte) Reader

NewReader creates a Reader over buf with the limit set to the full buffer length in bits (8*len(buf)), mirroring upstream bs_init.

func NewReaderBits

func NewReaderBits(buf []byte, posBits, limitBits int) Reader

NewReaderBits creates a Reader over buf starting at posBits with an explicit bit limit, for callers that seek into a shared buffer (e.g. the bit reservoir) rather than starting at byte 0.

func (*Reader) Bits

func (r *Reader) Bits(n int) uint32

Bits reads the next n bits (n in [0,24]) MSB-first and advances the position, porting upstream get_bits exactly: the position always advances by n first, and a read that pushes it past the limit returns 0 and latches Overrun. Since pos never moves backward on its own, every read after that also lands past the limit and returns 0 too.

func (*Reader) Overrun

func (r *Reader) Overrun() bool

Overrun reports whether any read has ever advanced the position past the limit.

func (*Reader) Pos

func (r *Reader) Pos() int

Pos returns the current bit position.

func (*Reader) SetPos

func (r *Reader) SetPos(bits int)

SetPos sets the bit position directly, e.g. to rewind or seek within the buffer.

Jump to

Keyboard shortcuts

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