Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bamiaux/iobit
Package iobit provides primitives for reading & writing bits
https://github.com/bamiaux/iobit
bit go reader writer
Last synced: about 2 months ago
JSON representation
Package iobit provides primitives for reading & writing bits
- Host: GitHub
- URL: https://github.com/bamiaux/iobit
- Owner: bamiaux
- License: mit
- Created: 2013-01-30T21:41:35.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-04-18T07:35:05.000Z (over 7 years ago)
- Last Synced: 2024-06-29T03:32:09.395Z (3 months ago)
- Topics: bit, go, reader, writer
- Language: Go
- Homepage:
- Size: 50.8 KB
- Stars: 17
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# iobit [![GoDoc](https://godoc.org/github.com/bamiaux/iobit/web?status.png)](https://godoc.org/github.com/bamiaux/iobit) [![Build Status](https://travis-ci.org/bamiaux/iobit.png)](https://travis-ci.org/bamiaux/iobit)
Package iobit provides primitives for reading & writing bits The main purpose of this library is to remove the need to write custom bit-masks when reading or writing bitstreams, and to ease maintenance.Download:
```shell
go get github.com/bamiaux/iobit
```Full documentation at http://godoc.org/github.com/bamiaux/iobit
* * *
Package iobit provides primitives for reading & writing bitsThe main purpose of this library is to remove the need to write
custom bit-masks when reading or writing bitstreams, and to ease
maintenance. This is true especially when you need to read/write
data which is not aligned on bytes.Errors are sticky so you can check for errors after a chunk of
meaningful work rather than after every operation.For example, with iobit you can read an MPEG-TS PCR like this:
```
r := iobit.NewReader(buffer)
base := r.Uint64(33) // PCR base is 33-bits
r.Skip(6) // 6-bits are reserved
extension := r.Uint64(9) // PCR extension is 9-bits
```instead of:
```
base = uint64(buffer[0]) << 25
base |= uint64(buffer[1]) << 17
base |= uint64(buffer[2]) << 9
base |= uint64(buffer[3]) << 1
base |= buffer[4] >> 7
extension := uint16(buffer[4] & 0x1) << 8
extension |= buffer[5]
```and write it like this:
```
w := iobit.NewWriter(buffer)
w.PutUint64(33, base)
w.PutUint32(6, 0)
w.PutUint32(9, extension)
```