From 8d12a8d7592ee15d5ddc2136118ab750b4457cd1 Mon Sep 17 00:00:00 2001 From: BiSaXa <1669855+BiSaXa@users.noreply.github.com> Date: Sun, 11 Sep 2022 10:37:36 +0300 Subject: changed readme for new version --- README.md | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2954d37..b204345 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# BitReader [![Go Report Card](https://goreportcard.com/badge/github.com/bisaxa/bitreader)](https://goreportcard.com/report/github.com/bisaxa/bitreader) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/bisaxa/bitreader/blob/main/LICENSE) +# BitReader [![Go Report Card](https://goreportcard.com/badge/github.com/bisaxa/bitreader)](https://goreportcard.com/report/github.com/bisaxa/bitreader) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/bisaxa/bitreader/blob/main/LICENSE) [![Go Reference](https://pkg.go.dev/badge/github.com/bisaxa/bitreader.svg)](https://pkg.go.dev/github.com/bisaxa/bitreader) A simple bit reader with big/little-endian support for golang.\ Reads data from an existing byte array.\ Uses string manipulation (for now).\ @@ -15,24 +15,42 @@ $ go get github.com/bisaxa/bitreader ```go import "github.com/bisaxa/bitreader" -// data: []byte Data to read from byte array -// le: bool Little-endian(true) or big-endian(false) state +// data: io.Reader Data to read from a io stream +// le: bool Little-endian(true) or big-endian(false) state reader := bitreader.Reader(data, le) -// read first bit -state, err := reader.ReadBit() +// Read First Bit +state, err := reader.ReadBool() -// skip bits/bytes +// Skip Bits/Bytes err := reader.SkipBits(8) err := reader.SkipBytes(4) -// read bits -value, err := reader.ReadBits(11) +// Read Bits/Bytes +value, err := reader.ReadBytes(4) value, err := reader.ReadBits(64) // up to 64 bits + +// Wrapper functions +state := reader.TryReadBool() // bool +value := reader.TryReadInt1() // uint8 +value := reader.TryReadInt8() // uint8 +value := reader.TryReadInt16() // uint16 +value := reader.TryReadInt32() // uint32 +value := reader.TryReadInt64() // uint64 +value := reader.TryReadFloat32() // float32 +value := reader.TryReadFloat64() // float64 ``` ## Error Handling -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. +ReadBits(x), ReadBytes(x), ReadBool(), SkipBits(x) and SkipBytes(x) functions returns an error message when they don't work as expected. It is advised to always handle errors. \ +Wrapper functions, however, only returns the value and panics if an error is encountered. + +## Bug Report / Feature Request +Using [Github Issues](https://github.com/BiSaXa/BitReader/issues/new/choose), you can report a bug that you encountered and/or request a feature that you would like to be added. + +## Documentation + +Full documentation can be found in https://pkg.go.dev/github.com/bisaxa/bitreader ## License This project is licensed under [MIT License](LICENSE). \ No newline at end of file -- cgit v1.2.3 From 1c7fe6c4047b137b9513a35c0db0c4b3380a5041 Mon Sep 17 00:00:00 2001 From: BiSaXa <1669855+BiSaXa@users.noreply.github.com> Date: Sun, 11 Sep 2022 10:37:54 +0300 Subject: slight change for go doc --- bitreader.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bitreader.go b/bitreader.go index 3fbc221..a56aab8 100644 --- a/bitreader.go +++ b/bitreader.go @@ -15,11 +15,16 @@ import ( // ReaderType is the main structure of our Reader. // Whenever index == 0, we need to read a new byte from stream into curByte +// +// stream io.Reader The underlying stream we're reading bytes from +// index uint18 The current index into the byte [0-7] +// curByte byte The byte we're currently reading from +// le bool Whether to read in little-endian order type ReaderType struct { - stream io.Reader // The underlying stream we're reading bytes from - index uint8 // The current index into the byte [0-7] - curByte byte // The byte we're currently reading from - le bool // Whether to read in little-endian order + stream io.Reader + index uint8 + curByte byte + le bool } // Reader is the main constructor that creates the ReaderType object -- cgit v1.2.3