https://github.com/as/bo
Package bo (byte order) provides functions for quickly serializing integers
https://github.com/as/bo
Last synced: 6 months ago
JSON representation
Package bo (byte order) provides functions for quickly serializing integers
- Host: GitHub
- URL: https://github.com/as/bo
- Owner: as
- License: mit
- Created: 2014-11-17T03:03:41.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-02-16T23:12:05.000Z (over 9 years ago)
- Last Synced: 2024-06-21T02:55:46.267Z (about 2 years ago)
- Language: Go
- Size: 585 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## What
Package bo (byte order) provides functions for packing and unpacking 16, 32, and 64 bit integers
to and from byte slices.
## How
The first 8 letters of the alphabet
```
b := make([]byte, 8)
ad := int32(0x41424344)
eh := int32(0x45464748)
bo.P32b(b, ad)
bo.P32b(b[4:], eh)
fmt.Printf("%v\n", string(b))
// ABCDEFGH
```
## Why
bo was written to pack data quickly.
bo runs 40% slower than inline C but 2200% faster than go package encoding/binary.
run bench/mark.sh to benchmark on your own machine.
## Install and Benchmark
```
git clone https://github.com/as/bo
cd bo/bench/
chmod u+x ./mark.sh
./mark.sh # needs gcc and go compiler
```