OSDN Git Service

Merge pull request #201 from Bytom/v0.1
[bytom/vapor.git] / vendor / github.com / multiformats / go-multiaddr / varint.go
diff --git a/vendor/github.com/multiformats/go-multiaddr/varint.go b/vendor/github.com/multiformats/go-multiaddr/varint.go
deleted file mode 100644 (file)
index b8b1507..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-package multiaddr
-
-import (
-       "encoding/binary"
-       "fmt"
-       "math/bits"
-)
-
-// VarintSize returns the size (in bytes) of `num` encoded as a varint.
-func VarintSize(num int) int {
-       bits := bits.Len(uint(num))
-       q, r := bits/7, bits%7
-       size := q
-       if r > 0 || size == 0 {
-               size++
-       }
-       return size
-}
-
-// CodeToVarint converts an integer to a varint-encoded []byte
-func CodeToVarint(num int) []byte {
-       buf := make([]byte, VarintSize(num))
-       n := binary.PutUvarint(buf, uint64(num))
-       return buf[:n]
-}
-
-// VarintToCode converts a varint-encoded []byte to an integer protocol code
-func VarintToCode(buf []byte) int {
-       num, _, err := ReadVarintCode(buf)
-       if err != nil {
-               panic(err)
-       }
-       return num
-}
-
-// ReadVarintCode reads a varint code from the beginning of buf.
-// returns the code, and the number of bytes read.
-func ReadVarintCode(buf []byte) (int, int, error) {
-       num, n := binary.Uvarint(buf)
-       if n < 0 {
-               return 0, 0, fmt.Errorf("varints larger than uint64 not yet supported")
-       }
-       return int(num), n, nil
-}