// Copyright 2017 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package catmsg// This file implements varint encoding analogous to the one in encoding/binary.// We need a string version of this function, so we add that here and then add// the rest for consistency.importvar ( errIllegalVarint = errors.New("catmsg: illegal varint") errVarintTooLarge = errors.New("catmsg: varint too large for uint64"))const maxVarintBytes = 10// maximum length of a varint// encodeUint encodes x as a variable-sized integer into buf and returns the// number of bytes written. buf must be at least maxVarintBytes longfunc encodeUint( []byte, uint64) ( int) {for ; > 127; ++ { [] = 0x80 | uint8(&0x7F) >>= 7 } [] = uint8() ++return}func decodeUintString( string) ( uint64, int, error) { := 0for := uint(0); < 64; += 7 {if >= len() {return0, , errIllegalVarint } := uint64([]) ++ |= ( & 0x7F) << if &0x80 == 0 {return , , nil } }return0, , errVarintTooLarge}func decodeUint( []byte) ( uint64, int, error) { := 0for := uint(0); < 64; += 7 {if >= len() {return0, , errIllegalVarint } := uint64([]) ++ |= ( & 0x7F) << if &0x80 == 0 {return , , nil } }return0, , errVarintTooLarge}
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.