binpacker
CategoryData Structures and Algorithms
SubcategoryBit-packing and Compression
Stars0
Binary packer and unpacker helps user build custom binary stream
About binpacker
binpacker

A binary packer and unpacker.
Install
go get github.com/zhuangsirui/binpacker
Examples
Packer
buffer := new(bytes.Buffer)
packer := binpacker.NewPacker(binary.BigEndian, buffer)
packer.PushByte(0x01)
packer.PushBytes([]byte{0x02, 0x03})
packer.PushUint16(math.MaxUint16)
// You can push data like this
buffer := new(bytes.Buffer)
packer := binpacker.NewPacker(binary.BigEndian, buffer)
packer.PushByte(0x01).PushBytes([]byte{0x02, 0x03}).PushUint16(math.MaxUint16)
packer.Error() // Make sure error is nil
Unpacker
Example data
buffer := new(bytes.Buffer)
packer := binpacker.NewPacker(binary.BigEndian, buffer)
unpacker := binpacker.NewUnpacker(binary.BigEndian, buffer)
packer.PushByte(0x01)
packer.PushUint16(math.MaxUint16)
var val1 byte
var val2 uint16
var err error
val1, err = unpacker.ShiftByte()
val2, err = unpacker.ShiftUint16()
var val1 byte
var val2 uint16
var err error
unpacker.FetchByte(&val1).FetchUint16(&val2)
unpacker.Error() // Make sure error is nil
Frequently Asked Questions
What is binpacker?
binpacker is a Data Structures and Algorithms library for the Go programming language. Binary packer and unpacker helps user build custom binary stream
How do I install binpacker?
Install binpacker with the Go module system using `go get zhuangsirui/binpacker`. Check the repository for the current installation instructions.
What category does binpacker belong to?
binpacker is listed under Data Structures and Algorithms, specifically Bit-packing and Compression.