GO語言"encoding/binary"包中"PutVarint"函數的用法及代碼示例。
用法:
func PutVarint(buf []byte, x int64) int
PutVarint 將 int64 編碼為 buf 並返回寫入的字節數。如果緩衝區太小,PutVarint 會Panics。
例子:
package main
import (
"encoding/binary"
"fmt"
)
func main() {
buf := make([]byte, binary.MaxVarintLen64)
for _, x := range []int64{-65, -64, -2, -1, 0, 1, 2, 63, 64} {
n := binary.PutVarint(buf, x)
fmt.Printf("%x\n", buf[:n])
}
}
輸出:
8101 7f 03 01 00 02 04 7e 8001
相關用法
- GO PutUvarint用法及代碼示例
- GO ParseAddress用法及代碼示例
- GO PlainAuth用法及代碼示例
- GO Print用法及代碼示例
- GO ParseUint用法及代碼示例
- GO ParseIP用法及代碼示例
- GO Pow10用法及代碼示例
- GO Printf用法及代碼示例
- GO ParseMediaType用法及代碼示例
- GO ParseInt用法及代碼示例
- GO ParseCIDR用法及代碼示例
- GO Perm用法及代碼示例
- GO Pipe用法及代碼示例
- GO ParseInLocation用法及代碼示例
- GO PathUnescape用法及代碼示例
- GO ParseDuration用法及代碼示例
- GO ParseFile用法及代碼示例
- GO Parse用法及代碼示例
- GO Pool用法及代碼示例
- GO Println用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 PutVarint。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。