func (w *Writer) PutBe16(val uint16) {
	w.PutUint32(16, uint32(val))
}
PutBe16 writes 16 bits in big-endian order.
package iobit
import (
	"encoding/binary"
	"errors"
)
type Writer struct {
	dst   []byte
	cache uint64
	fill  uint
	idx   int
}
var (
	ErrOverflow = errors.New("bit overflow")
	ErrUnderflow = errors.New("bit underflow")
)
func NewWriter(dst []byte) Writer {
	return Writer{dst: dst}
}
func (w *Writer) PutUint32(bits uint, val uint32) {
	u := uint64(val) << (64 - bits)
	if w.fill > 64-bits {
		if w.idx+4 <= len(w.dst) {
			binary.BigEndian.PutUint32(w.dst[w.idx:], uint32(w.cache>>32))
		}
		w.idx += 4
		w.fill -= 32
		w.cache <<= 32
	}
	u >>= w.fill
	w.fill += bits
	w.cache |= u
}
func (w *Writer) PutUint64(bits uint, val uint64) {
	if bits > 32 {
		bits -= 32
		w.PutBe32(uint32(val >> bits))
	}
	w.PutUint32(bits, uint32(val))
}
func (w *Writer) PutBit(val bool) {
	v := uint32(0)
	if val {
		v = 1
	}
	w.PutUint32(1, v)
}
func (w *Writer) PutByte(val byte) {
	w.PutUint32(8, uint32(val))
}
func (w *Writer) PutLe16(val uint16) {
	w.PutUint32(16, uint32(bswap16(val)))
}