erigon-pulse/cmd/lightclient/sentinel/proto/util.go
a 9f6fd488d2
[cl lightclient] - packet decoding & ssz code generation (#5558)
* added subscription to gossip

* added all handlers with logs

* disconnecting from peers with goodbye message received

* added time out for stream

* wip

* Remove unused

* remove extra structs

* status handler

* minor clean up

* add structs for altair light client

* begin writing out altair light client sync protocol to figure out what other structs are needed

* remove sszgen

* cleanup pt 1

* cleanup pt 2

* remove go 1.19 function

* less ambigious variable name

* run go fmt

* rename snappy_ssz to ssz_snappy to better align with wire name

* move more structs over

* poof set deadline

Co-authored-by: Enrique Jose Avila Asapche <eavilaasapche@gmail.com>
Co-authored-by: a <a@a.a>
2022-09-29 19:07:57 +02:00

31 lines
535 B
Go

package proto
import (
"errors"
"io"
)
func ReadUvarint(r io.Reader) (uint64, uint64, error) {
var x uint64
var s uint
var total uint64
bs := [1]byte{}
for i := 0; i < 10; i++ {
_, err := r.Read(bs[:])
if err != nil {
return x, total, err
}
b := bs[0]
total = total + 1
if b < 0x80 {
if i == 10-1 && b > 1 {
return x, total, errors.New("readUvarint: overflow")
}
return x | uint64(b)<<s, total, nil
}
x |= uint64(b&0x7f) << s
s += 7
}
return x, total, errors.New("readUvarint: overflow")
}