aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-09-15 21:09:47 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-09-15 21:09:47 +0300
commita344d1fa82e1f76c71a71bfaee7c81cbbe1e1d02 (patch)
treeee64098e263e04afac513d9a5d60b4c6eabb128a /README.md
parentchange readme for LGPL v2.1 (diff)
downloadbitreader-a344d1fa82e1f76c71a71bfaee7c81cbbe1e1d02.tar.gz
bitreader-a344d1fa82e1f76c71a71bfaee7c81cbbe1e1d02.tar.bz2
bitreader-a344d1fa82e1f76c71a71bfaee7c81cbbe1e1d02.zip
revamped bitreader; with new functionality and bug fixes
Diffstat (limited to 'README.md')
-rw-r--r--README.md76
1 files changed, 42 insertions, 34 deletions
diff --git a/README.md b/README.md
index f88c216..6264cd4 100644
--- a/README.md
+++ b/README.md
@@ -1,64 +1,72 @@
1# BitReader [![Go Report Card](https://goreportcard.com/badge/github.com/pektezol/bitreader)](https://goreportcard.com/report/github.com/pektezol/bitreader) [![License: LGPL 2.1](https://img.shields.io/badge/License-LGPL_v2.1-blue.svg)](https://github.com/pektezol/bitreader/blob/main/LICENSE) [![Go Reference](https://pkg.go.dev/badge/github.com/pektezol/bitreader.svg)](https://pkg.go.dev/github.com/pektezol/bitreader) 1# BitReader [![Go Reference](https://pkg.go.dev/badge/github.com/pektezol/bitreader.svg)](https://pkg.go.dev/github.com/pektezol/bitreader) [![Go Report Card](https://goreportcard.com/badge/github.com/pektezol/bitreader)](https://goreportcard.com/report/github.com/pektezol/bitreader) [![License: LGPL 2.1](https://img.shields.io/badge/License-LGPL_v2.1-blue.svg)](https://github.com/pektezol/bitreader/blob/main/LICENSE)
2A simple bit reader with big/little-endian support for golang.\ 2A simple bit reader with big/little-endian support for golang.
3Reads stream data from an io.Reader; can read from os.File and a byte array with bytes.NewReader(array).\
4Uses bitwise operations.\
5Support reading up to 64 bits at one time.\
6Includes wrapper functions for most used data types.\
7Error checking on all but wrapper functions.
8 3
9## Installation 4## Installation
10```bash 5```bash
11$ go get github.com/pektezol/bitreader 6$ go get github.com/pektezol/bitreader
12``` 7```
13 8
14## Usage 9## Usage Examples
15 10
16```go 11```go
17import "github.com/pektezol/bitreader" 12import "github.com/pektezol/bitreader"
18 13
19// data: io.Reader Data to read from an io stream 14// ioStream: io.Reader Data to read from an io stream
20// le: bool Little-endian(true) or big-endian(false) state 15// byteStream: []byte Data to read from a byte slice
21reader := bitreader.Reader(data, le) 16// littleEndian: bool Little-endian(true) or big-endian(false) state
17reader := bitreader.NewReader(ioStream, le)
18reader := bitreader.NewReaderFromBytes(byteStream, le)
19
20// Fork Reader, Copies Current Reader
21newReader, err := reader.Fork()
22
23// Read Total Number of Bits Left
24bits, err := reader.ReadRemainingBits()
22 25
23// Read First Bit 26// Read First Bit
24state, err := reader.ReadBool() 27state, err := reader.ReadBool()
25 28
26// Skip Bits/Bytes
27err := reader.SkipBits(8)
28err := reader.SkipBytes(4)
29
30// Read Bits/Bytes 29// Read Bits/Bytes
31value, err := reader.ReadBytes(4) // up to 8 bytes
32value, err := reader.ReadBits(64) // up to 64 bits 30value, err := reader.ReadBits(64) // up to 64 bits
31value, err := reader.ReadBytes(8) // up to 8 bytes
33 32
34// Read String 33// Read String
35text, err := reader.ReadString() // null-terminated 34text, err := reader.ReadString() // null-terminated
36text, err := reader.ReadStringLen(256) // length-specified 35text, err := reader.ReadStringLength(256) // length-specified
37 36
38// Read Bits/Bytes into Slice 37// Read Bits/Bytes into Slice
39arr, err := reader.ReadBitsToSlice(128) 38arr, err := reader.ReadBitsToSlice(128)
40arr, err := reader.ReadBytesToSlice(64) 39arr, err := reader.ReadBytesToSlice(64)
41 40
41// Skip Bits/Bytes
42err := reader.SkipBits(8)
43err := reader.SkipBytes(4)
44
42// Wrapper functions 45// Wrapper functions
43text := reader.TryReadString() // string 46state := reader.TryReadBool() // bool
44text := reader.TryReadStringLen(64) // string 47value := reader.TryReadInt1() // uint8
45arr := reader.ReadBitsToSlice(128) // []byte 48value := reader.TryReadUInt8() // uint8
46arr := reader.ReadBytesToSlice(64) // []byte 49value := reader.TryReadSInt8() // int8
47state := reader.TryReadBool() // bool 50value := reader.TryReadUInt16() // uint16
48value := reader.TryReadInt1() // uint8 51value := reader.TryReadSInt16() // int16
49value := reader.TryReadInt8() // uint8 52value := reader.TryReadUInt32() // uint32
50value := reader.TryReadInt16() // uint16 53value := reader.TryReadSInt32() // int32
51value := reader.TryReadInt32() // uint32 54value := reader.TryReadUInt64() // uint64
52value := reader.TryReadInt64() // uint64 55value := reader.TryReadSInt64() // int64
53value := reader.TryReadFloat32() // float32 56value := reader.TryReadFloat32() // float32
54value := reader.TryReadFloat64() // float64 57value := reader.TryReadFloat64() // float64
55value := reader.TryReadBits(64) // uint64 58value := reader.TryReadBits(64) // uint64
56value := reader.TryReadBytes(8) // uint64 59value := reader.TryReadBytes(8) // uint64
60text := reader.TryReadString() // string
61text := reader.TryReadStringLength(64) // string
62arr := reader.TryReadBitsToSlice(1024) // []byte
63arr := reader.TryReadBytesToSlice(128) // []byte
64bits := reader.TryReadRemainingBits() // uint64
57``` 65```
58 66
59## Error Handling 67## Error Handling
60ReadBits(x), ReadBytes(x), ReadBool(), ReadString(), ReadStringLen(x), ReadBitsToSlice(x), ReadBytesToSlice(x), SkipBits(x) and SkipBytes(x) functions returns an error message when they don't work as expected. It is advised to always handle errors. \ 68All ReadXXX(), SkipXXX() and Fork() functions returns an error message when they don't work as expected. It is advised to always handle errors. \
61Wrapper functions, however, only returns the value and panics if an error is encountered. 69Wrapper functions, however, only returns the value and panics if an error is encountered, for the sake of ease of use.
62 70
63## Bug Report / Feature Request 71## Bug Report / Feature Request
64Using [Github Issues](https://github.com/pektezol/BitReader/issues/new/choose), you can report a bug that you encountered and/or request a feature that you would like to be added. 72Using [Github Issues](https://github.com/pektezol/BitReader/issues/new/choose), you can report a bug that you encountered and/or request a feature that you would like to be added.