func (d *Decompressor) dodTimestampBitN() (n uint, err error) {
	var dod byte
	for i := 0; i < 4; i++ {
		dod <<= 1
		b, err := d.br.readBit()
		if err != nil {
			return 0, err
		}
		if b {
			dod |= 1
		} else {
			break
		}
	}
	switch dod {
	case 0x00:  
		return 0, nil
	case 0x02:  
		return 7, nil
	case 0x06:  
		return 9, nil
	case 0x0E:  
		return 12, nil
	case 0x0F:  
		return 32, nil
	default:
		return 0, errors.New("invalid bit header for bit length to read")
	}
}
returning the amount of delta-of-delta timestamp bits.
package gorilla
import (
	"errors"
	"fmt"
	"io"
	"math"
)
type Decompressor struct {
	br            *bitReader
	header        uint32
	t             uint32
	delta         uint32
	leadingZeros  uint8
	trailingZeros uint8
	value         uint64
}
func NewDecompressor(r io.Reader) (d *Decompressor, header uint32, err error) {
	d = &Decompressor{
		br: newBitReader(r),
	}
	h, err := d.br.readBits(32)
	if err != nil {
		return nil, 0, fmt.Errorf("failed to decode header: %w", err)
	}
	d.header = uint32(h)
	return d, d.header, nil
}
func (d *Decompressor) Iterator() *DecompressIterator {
	return &DecompressIterator{0, 0, nil, d}
}
type DecompressIterator struct {
	t   uint32
	v   float64
	err error
	d   *Decompressor
}
func (di *DecompressIterator) Next() (t uint32, v float64) {
	return di.t, di.v
}
func (di *DecompressIterator) Err() error {
	if errors.Is(di.err, io.EOF) {
		return nil
	}
	return di.err
}
func (di *DecompressIterator) HasNext() bool {
	if di.d.t == 0 {
		di.t, di.v, di.err = di.d.decompressFirst()
	} else {
		di.t, di.v, di.err = di.d.decompress()
	}
	return di.err == nil
}
func (d *Decompressor) decompressFirst() (t uint32, v float64, err error) {
	delta, err := d.br.readBits(firstDeltaBits)
	if err != nil {
		return 0, 0, fmt.Errorf("failed to decompress delta at first: %w", err)
	}
	if delta == 1<<firstDeltaBits-1 {
		return 0, 0, io.EOF
	}
	value, err := d.br.readBits(64)
	if err != nil {
		return 0, 0, fmt.Errorf("failed to decompress value at first: %w", err)
	}
	d.delta = uint32(delta)
	d.t = d.header + d.delta
	d.value = value
	return d.t, math.Float64frombits(d.value), nil
}
func (d *Decompressor) decompress() (t uint32, v float64, err error) {
	t, err = d.decompressTimestamp()
	if err != nil {
		return 0, 0, fmt.Errorf("failed to decompress timestamp: %w", err)
	}
	v, err = d.decompressValue()
	if err != nil {
		return 0, 0, fmt.Errorf("failed to decompress value: %w", err)
	}
	return t, v, nil
}
func (d *Decompressor) decompressTimestamp() (uint32, error) {
	n, err := d.dodTimestampBitN()
	if err != nil {
		return 0, err
	}
	if n == 0 {
		d.t += d.delta
		return d.t, nil
	}
	bits, err := d.br.readBits(int(n))
	if err != nil {
		return 0, fmt.Errorf("failed to read timestamp: %w", err)
	}
	if n == 32 && bits == 0xFFFFFFFF {
		return 0, io.EOF
	}
	var dod int64 = int64(bits)
	if n != 32 && 1<<(n-1) < int64(bits) {
		dod = int64(bits - 1<<n)
	}
	d.delta += uint32(dod)
	d.t += d.delta
	return d.t, nil
}