Skip to content

wiggin77/nibs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nibs

GoDoc Build Status

Nibs is a Go package for reading streams of bytes in nibbles. Each nibble can be a number of bits in the range 1 bit to 64 bits inclusive.

Usage

// provide an io.Reader
b := []byte("this is a test")
buf := bytes.NewReader(b)

// create instance of Nibs
nib := nibs.New(buf)

// read until io.EOF,
for {
  n, err := nib.Nibble8(4)
  if err != nil {
    break
  }
  fmt.Printf("nibbled 4 bits: %d", n)
}

// once EOF is reached, there will be bits left over
// if nibble sizes do not divide evenly into the `NibbleXX`
// return type. Use `BitsRemaining` to determine how many.
remaining, err := nib.BitsRemaining()
if err == nil && remaining > 0 {
  n, err := nib.Nibble(remaining)
  if err == nil {
    fmt.Printf("nibbled %d remaining bits: %d", remaining, n)
  }
}

Releases

No releases published

Packages

No packages published

Languages