package qpack// copied from the Go standard library HPACK implementationimportvar errVarintOverflow = errors.New("varint integer overflow")// appendVarInt appends i, as encoded in variable integer form using n// bit prefix, to dst and returns the extended buffer.//// See// http://http2.github.io/http2-spec/compression.html#integer.representationfunc appendVarInt( []byte, byte, uint64) []byte { := uint64((1 << ) - 1)if < {returnappend(, byte()) } = append(, byte()) -= for ; >= 128; >>= 7 { = append(, byte(0x80|(&0x7f))) }returnappend(, byte())}// readVarInt reads an unsigned variable length integer off the// beginning of p. n is the parameter as described in// http://http2.github.io/http2-spec/compression.html#rfc.section.5.1.//// n must always be between 1 and 8.//// The returned remain buffer is either a smaller suffix of p, or err != nil.// The error is errNeedMore if p doesn't contain a complete integer.func readVarInt( byte, []byte) ( uint64, []byte, error) {if < 1 || > 8 {panic("bad n") }iflen() == 0 {return0, , errNeedMore } = uint64([0])if < 8 { &= (1 << uint64()) - 1 }if < (1<<uint64())-1 {return , [1:], nil } := = [1:]varuint64forlen() > 0 { := [0] = [1:] += uint64(&127) << if &128 == 0 {return , , nil } += 7if >= 63 { // TODO: proper overflow check. making this up.return0, , errVarintOverflow } }return0, , errNeedMore}
The pages are generated with Goldsv0.8.2. (GOOS=linux 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 @zigo_101 (reachable from the left QR code) to get the latest news of Golds.