golang binary包

binary包是 golang的二进制包,

a := "hello,this is a first sentence."
//b := "hello,this is a second sentence."

//实例化一个 io容器
by := bytes.NewBuffer([]byte{})
//往里面写入4个字节的数据
binary.Write(by,binary.BigEndian,int32(len(a)))

var dataLen int32
//读取4个字节
binary.Read(by,binary.BigEndian,&dataLen)
fmt.Println(dataLen)
posted @ 2021-10-12 18:33  梁天  阅读(627)  评论(0编辑  收藏  举报