diff options
| -rw-r--r-- | README.md | 10 |
1 files changed, 6 insertions, 4 deletions
| @@ -16,7 +16,7 @@ $ go get github.com/pektezol/bitreader | |||
| 16 | ```go | 16 | ```go |
| 17 | import "github.com/pektezol/bitreader" | 17 | import "github.com/pektezol/bitreader" |
| 18 | 18 | ||
| 19 | // data: io.Reader Data to read from a io stream | 19 | // data: io.Reader Data to read from an io stream |
| 20 | // le: bool Little-endian(true) or big-endian(false) state | 20 | // le: bool Little-endian(true) or big-endian(false) state |
| 21 | reader := bitreader.Reader(data, le) | 21 | reader := bitreader.Reader(data, le) |
| 22 | 22 | ||
| @@ -32,10 +32,12 @@ value, err := reader.ReadBytes(4) | |||
| 32 | value, err := reader.ReadBits(64) // up to 64 bits | 32 | value, err := reader.ReadBits(64) // up to 64 bits |
| 33 | 33 | ||
| 34 | // Read String | 34 | // Read String |
| 35 | value, err := reader.ReadString() // null-terminated | 35 | text, err := reader.ReadString() // null-terminated |
| 36 | text, err := reader.ReadStringLen(256) // length-specified | ||
| 36 | 37 | ||
| 37 | // Wrapper functions | 38 | // Wrapper functions |
| 38 | text := reader.ReadString() // string | 39 | text := reader.TryReadString() // string |
| 40 | text := reader.TryReadStringLen(64) // string | ||
| 39 | state := reader.TryReadBool() // bool | 41 | state := reader.TryReadBool() // bool |
| 40 | value := reader.TryReadInt1() // uint8 | 42 | value := reader.TryReadInt1() // uint8 |
| 41 | value := reader.TryReadInt8() // uint8 | 43 | value := reader.TryReadInt8() // uint8 |
| @@ -47,7 +49,7 @@ value := reader.TryReadFloat64() // float64 | |||
| 47 | ``` | 49 | ``` |
| 48 | 50 | ||
| 49 | ## Error Handling | 51 | ## Error Handling |
| 50 | ReadBits(x), ReadBytes(x), ReadBool(), ReadString(), SkipBits(x) and SkipBytes(x) functions returns an error message when they don't work as expected. It is advised to always handle errors. \ | 52 | ReadBits(x), ReadBytes(x), ReadBool(), ReadString(), ReadStringLen(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. \ |
| 51 | Wrapper functions, however, only returns the value and panics if an error is encountered. | 53 | Wrapper functions, however, only returns the value and panics if an error is encountered. |
| 52 | 54 | ||
| 53 | ## Bug Report / Feature Request | 55 | ## Bug Report / Feature Request |