1 Star 0 Fork 0

sqos / beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bytes.go 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
Steffen Siering 提交于 2016-10-24 10:46 . minor cleanups (#2819)
package common
import (
"bytes"
"errors"
"fmt"
)
// Byte order utilities
func BytesNtohs(b []byte) uint16 {
return uint16(b[0])<<8 | uint16(b[1])
}
func BytesNtohl(b []byte) uint32 {
return uint32(b[0])<<24 | uint32(b[1])<<16 |
uint32(b[2])<<8 | uint32(b[3])
}
func BytesHtohl(b []byte) uint32 {
return uint32(b[3])<<24 | uint32(b[2])<<16 |
uint32(b[1])<<8 | uint32(b[0])
}
func BytesNtohll(b []byte) uint64 {
return uint64(b[0])<<56 | uint64(b[1])<<48 |
uint64(b[2])<<40 | uint64(b[3])<<32 |
uint64(b[4])<<24 | uint64(b[5])<<16 |
uint64(b[6])<<8 | uint64(b[7])
}
// Ipv4_Ntoa transforms an IP4 address in it's dotted notation
func IPv4Ntoa(ip uint32) string {
return fmt.Sprintf("%d.%d.%d.%d",
byte(ip>>24), byte(ip>>16),
byte(ip>>8), byte(ip))
}
// ReadString extracts the first null terminated string from
// a slice of bytes.
func ReadString(s []byte) (string, error) {
i := bytes.IndexByte(s, 0)
if i < 0 {
return "", errors.New("No string found")
}
res := string(s[:i])
return res, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v6.1.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891