Skip to content

Commit

Permalink
interoperable uvarints. (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed Jul 29, 2020
1 parent 0a87fa5 commit 7083218
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion varint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"

pool "github.com/libp2p/go-buffer-pool"
"github.com/multiformats/go-varint"
)

// varintWriter is the underlying type that implements the Writer interface.
Expand Down Expand Up @@ -115,7 +116,7 @@ func (s *varintReader) NextMsgLen() (int, error) {

func (s *varintReader) nextMsgLen() (int, error) {
if s.next == -1 {
length, err := binary.ReadUvarint(s.br)
length, err := varint.ReadUvarint(s.br)
if err != nil {
return 0, err
}
Expand Down
6 changes: 4 additions & 2 deletions varint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/binary"
"io"
"testing"

"github.com/multiformats/go-varint"
)

func TestVarintReadWrite(t *testing.T) {
Expand Down Expand Up @@ -46,7 +48,7 @@ func SubtestVarintWrite(t *testing.T, msg []byte) {
bb := buf.Bytes()

sbr := simpleByteReader{R: buf}
length, err := binary.ReadUvarint(&sbr)
length, err := varint.ReadUvarint(&sbr)
if err != nil {
t.Fatal(err)
}
Expand All @@ -57,7 +59,7 @@ func SubtestVarintWrite(t *testing.T, msg []byte) {
}

lbuf := make([]byte, binary.MaxVarintLen64)
n := binary.PutUvarint(lbuf, length)
n := varint.PutUvarint(lbuf, length)

bblen := int(length) + n
t.Logf("checking wrote (%d + %d) bytes", length, n)
Expand Down

0 comments on commit 7083218

Please sign in to comment.