GO語言"encoding/binary"包中"Uvarint"函數的用法及代碼示例。
用法:
func Uvarint(buf []byte)(uint64, int)
Uvarint 從 buf 解碼一個 uint64 並返回該值和讀取的字節數 (> 0)。如果發生錯誤,則值為 0,字節數 n <= 0 表示:
n == 0: buf too small n < 0: value larger than 64 bits (overflow) and -n is the number of bytes read
例子:
package main
import (
"encoding/binary"
"fmt"
)
func main() {
inputs := [][]byte{
{0x01},
{0x02},
{0x7f},
{0x80, 0x01},
{0xff, 0x01},
{0x80, 0x02},
}
for _, b := range inputs {
x, n := binary.Uvarint(b)
if n != len(b) {
fmt.Println("Uvarint did not consume all of in")
}
fmt.Println(x)
}
}
輸出:
1 2 127 128 255 256
相關用法
- GO UDPConn.WriteTo用法及代碼示例
- GO Unmarshal用法及代碼示例
- GO URL.Hostname用法及代碼示例
- GO URL.EscapedPath用法及代碼示例
- GO UnaryOp用法及代碼示例
- GO URL.Port用法及代碼示例
- GO URL.ResolveReference用法及代碼示例
- GO URL.Query用法及代碼示例
- GO URL.Redacted用法及代碼示例
- GO Unsetenv用法及代碼示例
- GO URL.Parse用法及代碼示例
- GO Unquote用法及代碼示例
- GO Unwrap用法及代碼示例
- GO UnquoteChar用法及代碼示例
- GO URL.String用法及代碼示例
- GO UnixMilli用法及代碼示例
- GO URL.UnmarshalBinary用法及代碼示例
- GO UnescapeString用法及代碼示例
- GO URL.EscapedFragment用法及代碼示例
- GO Unix用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Uvarint。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。