diff options
| author | BiSaXa <1669855+BiSaXa@users.noreply.github.com> | 2022-09-04 14:53:07 +0300 |
|---|---|---|
| committer | BiSaXa <1669855+BiSaXa@users.noreply.github.com> | 2022-09-04 14:53:07 +0300 |
| commit | a08480e8cd5df93a953323b400914520d5963660 (patch) | |
| tree | 964a157eb318d544967e8e20e42dd7c7526dc0c4 /README.md | |
| parent | specify little endian, easier reader construct (diff) | |
| download | bitreader-a08480e8cd5df93a953323b400914520d5963660.tar.gz bitreader-a08480e8cd5df93a953323b400914520d5963660.tar.bz2 bitreader-a08480e8cd5df93a953323b400914520d5963660.zip | |
added skipbytes, 64 bit support for readbits, new readme
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 37 |
1 files changed, 37 insertions, 0 deletions
| @@ -1 +1,38 @@ | |||
| 1 | # BitReader | 1 | # BitReader |
| 2 | A simple bit reader with big/little-endian support for golang.\ | ||
| 3 | Reads data from an existing byte array.\ | ||
| 4 | Uses string manipulation (for now).\ | ||
| 5 | Support reading up to 64 bits at one time.\ | ||
| 6 | Checking for overflowing the data. | ||
| 7 | |||
| 8 | ## Installation | ||
| 9 | ```bash | ||
| 10 | $ go get github.com/bisaxa/bitreader | ||
| 11 | ``` | ||
| 12 | |||
| 13 | ## Usage | ||
| 14 | |||
| 15 | ```go | ||
| 16 | import "github.com/bisaxa/bitreader" | ||
| 17 | |||
| 18 | // data: []byte Data to read from byte array | ||
| 19 | // le: bool Little-endian(true) or big-endian(false) state | ||
| 20 | reader := bitreader.Reader(data, le) | ||
| 21 | |||
| 22 | // read first bit | ||
| 23 | state, err := reader.ReadBit() | ||
| 24 | |||
| 25 | // skip bits/bytes | ||
| 26 | err := reader.SkipBits(8) | ||
| 27 | err := reader.SkipBytes(4) | ||
| 28 | |||
| 29 | // read bits | ||
| 30 | value, err := reader.ReadBits(11) | ||
| 31 | value, err := reader.ReadBits(64) // up to 64 bits | ||
| 32 | ``` | ||
| 33 | |||
| 34 | ## Error Handling | ||
| 35 | ReadBits(x), ReadBit(), SkipBits(x) and SkipBytes(x) functions returns an error message when they don't work as expected. It is advised to always handle errors. | ||
| 36 | |||
| 37 | ## License | ||
| 38 | This project is licensed under [MIT License](LICENSE). \ No newline at end of file | ||