aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2022-11-10 20:54:29 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2022-11-10 20:54:29 +0300
commitb0c0e97e53c150fbd763d4cc8f58b28837404ec6 (patch)
tree17e5f8c254d1110ab4338847fb539b57232b116e
parentadd ReadBytesToSlice() function (diff)
downloadbitreader-b0c0e97e53c150fbd763d4cc8f58b28837404ec6.tar.gz
bitreader-b0c0e97e53c150fbd763d4cc8f58b28837404ec6.tar.bz2
bitreader-b0c0e97e53c150fbd763d4cc8f58b28837404ec6.zip
added wrapper funcs for read bits/bytesv1.2.3
-rw-r--r--README.md2
-rw-r--r--bitreader.go20
2 files changed, 22 insertions, 0 deletions
diff --git a/README.md b/README.md
index 6cdb38c..1093153 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,8 @@ value := reader.TryReadInt32() // uint32
46value := reader.TryReadInt64() // uint64 46value := reader.TryReadInt64() // uint64
47value := reader.TryReadFloat32() // float32 47value := reader.TryReadFloat32() // float32
48value := reader.TryReadFloat64() // float64 48value := reader.TryReadFloat64() // float64
49value := reader.TryReadBits(64) // uint64
50value := reader.TryReadBytes(8) // uint64
49``` 51```
50 52
51## Error Handling 53## Error Handling
diff --git a/bitreader.go b/bitreader.go
index 33383e9..b9ac772 100644
--- a/bitreader.go
+++ b/bitreader.go
@@ -118,6 +118,26 @@ func (reader *ReaderType) TryReadFloat64() float64 {
118 return math.Float64frombits(value) 118 return math.Float64frombits(value)
119} 119}
120 120
121// TryReadBits is a wrapper function that returns the value of bits specified in the parameter.
122// Returns uint64. Panics on error.
123func (reader *ReaderType) TryReadBits(bits int) uint64 {
124 value, err := reader.ReadBits(bits)
125 if err != nil {
126 panic(err)
127 }
128 return value
129}
130
131// TryReadBytes is a wrapper function that returns the value of bits specified in the parameter.
132// Returns uint64. Panics on error.
133func (reader *ReaderType) TryReadBytes(bytes int) uint64 {
134 value, err := reader.ReadBytes(bytes)
135 if err != nil {
136 panic(err)
137 }
138 return value
139}
140
121// TryReadString is a wrapper function that returns the string 141// TryReadString is a wrapper function that returns the string
122// that is read until it is null-terminated. 142// that is read until it is null-terminated.
123func (reader *ReaderType) TryReadString() string { 143func (reader *ReaderType) TryReadString() string {