Source File
varint.go
Belonging Package
encoding/binary
package binary
import (
)
const (
MaxVarintLen16 = 3
MaxVarintLen32 = 5
MaxVarintLen64 = 10
)
func ( []byte) (uint64, int) {
var uint64
var uint
for , := range {
if < 0x80 {
if >= MaxVarintLen64 || == MaxVarintLen64-1 && > 1 {
return 0, -( + 1) // overflow
}
return | uint64()<<, + 1
}
|= uint64(&0x7f) <<
+= 7
}
return 0, 0
}
func ( []byte, int64) int {
:= uint64() << 1
if < 0 {
= ^
}
return PutUvarint(, )
}
func ( io.ByteReader) (uint64, error) {
var uint64
var uint
for := 0; < MaxVarintLen64; ++ {
, := .ReadByte()
if != nil {
return ,
}
if < 0x80 {
if == MaxVarintLen64-1 && > 1 {
return , overflow
}
return | uint64()<<, nil
}
|= uint64(&0x7f) <<
+= 7
}
return , overflow
}
func ( io.ByteReader) (int64, error) {
, := ReadUvarint() // ok to continue in presence of error
:= int64( >> 1)
if &1 != 0 {
= ^
}
return ,
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |