aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bitreader.go16
-rw-r--r--bitreader_test.go22
2 files changed, 19 insertions, 19 deletions
diff --git a/bitreader.go b/bitreader.go
index e50f433..6b88709 100644
--- a/bitreader.go
+++ b/bitreader.go
@@ -368,18 +368,18 @@ func (reader *Reader) ReadBytes(bytes uint64) (uint64, error) {
368// 368//
369// Returns an error if there are no remaining bits. 369// Returns an error if there are no remaining bits.
370func (reader *Reader) ReadString() (string, error) { 370func (reader *Reader) ReadString() (string, error) {
371 var out string 371 var out []byte
372 for { 372 for {
373 value, err := reader.ReadBytes(1) 373 value, err := reader.ReadBytes(1)
374 if err != nil { 374 if err != nil {
375 return out, err 375 return string(out), err
376 } 376 }
377 if value == 0 { 377 if value == 0 {
378 break 378 break
379 } 379 }
380 out += string(rune(value)) 380 out = append(out, byte(value))
381 } 381 }
382 return out, nil 382 return string(out), nil
383} 383}
384 384
385// ReadStringLength is a function that reads every byte 385// ReadStringLength is a function that reads every byte
@@ -389,20 +389,20 @@ func (reader *Reader) ReadString() (string, error) {
389// 389//
390// Returns an error if there are no remaining bits. 390// Returns an error if there are no remaining bits.
391func (reader *Reader) ReadStringLength(length uint64) (string, error) { 391func (reader *Reader) ReadStringLength(length uint64) (string, error) {
392 var out string 392 var out []byte
393 var i uint64 393 var i uint64
394 for i = 0; i < length; i++ { 394 for i = 0; i < length; i++ {
395 value, err := reader.ReadBytes(1) 395 value, err := reader.ReadBytes(1)
396 if err != nil { 396 if err != nil {
397 return out, err 397 return string(out), err
398 } 398 }
399 if value == 0 { 399 if value == 0 {
400 reader.SkipBytes(length - 1 - i) 400 reader.SkipBytes(length - 1 - i)
401 break 401 break
402 } 402 }
403 out += string(rune(value)) 403 out = append(out, byte(value))
404 } 404 }
405 return out, nil 405 return string(out), nil
406} 406}
407 407
408// ReadBitsToSlice is a function that reads the specified amount of bits 408// ReadBitsToSlice is a function that reads the specified amount of bits
diff --git a/bitreader_test.go b/bitreader_test.go
index acd980e..588590a 100644
--- a/bitreader_test.go
+++ b/bitreader_test.go
@@ -1,5 +1,5 @@
1// BitReader is a simple bit reader with big/little-endian support for golang. 1// BitReader is a simple bit reader with big/little-endian support for golang.
2// %83.2 coerage 2// %83.6 coerage
3package bitreader 3package bitreader
4 4
5import ( 5import (
@@ -616,7 +616,7 @@ func TestReader_TryReadFloat64(t *testing.T) {
616 616
617func TestReader_TryReadBits(t *testing.T) { 617func TestReader_TryReadBits(t *testing.T) {
618 type args struct { 618 type args struct {
619 bits int 619 bits uint64
620 } 620 }
621 tests := []struct { 621 tests := []struct {
622 name string 622 name string
@@ -662,7 +662,7 @@ func TestReader_TryReadBits(t *testing.T) {
662 662
663func TestReader_TryReadBytes(t *testing.T) { 663func TestReader_TryReadBytes(t *testing.T) {
664 type args struct { 664 type args struct {
665 bytes int 665 bytes uint64
666 } 666 }
667 tests := []struct { 667 tests := []struct {
668 name string 668 name string
@@ -744,7 +744,7 @@ func TestReader_TryReadString(t *testing.T) {
744 744
745func TestReader_TryReadStringLength(t *testing.T) { 745func TestReader_TryReadStringLength(t *testing.T) {
746 type args struct { 746 type args struct {
747 length int 747 length uint64
748 } 748 }
749 tests := []struct { 749 tests := []struct {
750 name string 750 name string
@@ -803,7 +803,7 @@ func TestReader_TryReadStringLength(t *testing.T) {
803 803
804func TestReader_TryReadBitsToSlice(t *testing.T) { 804func TestReader_TryReadBitsToSlice(t *testing.T) {
805 type args struct { 805 type args struct {
806 bits int 806 bits uint64
807 } 807 }
808 tests := []struct { 808 tests := []struct {
809 name string 809 name string
@@ -875,7 +875,7 @@ func TestReader_TryReadBitsToSlice(t *testing.T) {
875 875
876func TestReader_TryReadBytesToSlice(t *testing.T) { 876func TestReader_TryReadBytesToSlice(t *testing.T) {
877 type args struct { 877 type args struct {
878 bytes int 878 bytes uint64
879 } 879 }
880 tests := []struct { 880 tests := []struct {
881 name string 881 name string
@@ -1012,7 +1012,7 @@ func TestReader_ReadBool(t *testing.T) {
1012 1012
1013func TestReader_ReadBits(t *testing.T) { 1013func TestReader_ReadBits(t *testing.T) {
1014 type args struct { 1014 type args struct {
1015 bits int 1015 bits uint64
1016 } 1016 }
1017 tests := []struct { 1017 tests := []struct {
1018 name string 1018 name string
@@ -1064,7 +1064,7 @@ func TestReader_ReadBits(t *testing.T) {
1064 1064
1065func TestReader_ReadBytes(t *testing.T) { 1065func TestReader_ReadBytes(t *testing.T) {
1066 type args struct { 1066 type args struct {
1067 bytes int 1067 bytes uint64
1068 } 1068 }
1069 tests := []struct { 1069 tests := []struct {
1070 name string 1070 name string
@@ -1158,7 +1158,7 @@ func TestReader_ReadString(t *testing.T) {
1158 1158
1159func TestReader_ReadStringLength(t *testing.T) { 1159func TestReader_ReadStringLength(t *testing.T) {
1160 type args struct { 1160 type args struct {
1161 length int 1161 length uint64
1162 } 1162 }
1163 tests := []struct { 1163 tests := []struct {
1164 name string 1164 name string
@@ -1223,7 +1223,7 @@ func TestReader_ReadStringLength(t *testing.T) {
1223 1223
1224func TestReader_ReadBitsToSlice(t *testing.T) { 1224func TestReader_ReadBitsToSlice(t *testing.T) {
1225 type args struct { 1225 type args struct {
1226 bits int 1226 bits uint64
1227 } 1227 }
1228 tests := []struct { 1228 tests := []struct {
1229 name string 1229 name string
@@ -1301,7 +1301,7 @@ func TestReader_ReadBitsToSlice(t *testing.T) {
1301 1301
1302func TestReader_ReadBytesToSlice(t *testing.T) { 1302func TestReader_ReadBytesToSlice(t *testing.T) {
1303 type args struct { 1303 type args struct {
1304 bytes int 1304 bytes uint64
1305 } 1305 }
1306 tests := []struct { 1306 tests := []struct {
1307 name string 1307 name string