Ai
1 Star 0 Fork 0

叶明志/golang练习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.go 782 Bytes
一键复制 编辑 原始数据 按行查看 历史
yemingzhi 提交于 2019-09-01 21:18 +08:00 . PracticesBySelf
package main
import(
"fmt"
"net"
"encoding/json"
"GolangLearnPractice1/day11/communicateP01/common/message"
)
type Transfer struct{
Conn net.Conn
Buf [8096]byte
}
func (this *Transfer)ReadPkg()(mes message.Message,err error) {
n,err:=this.Conn.Read(this.Buf[:])
if err!=nil{
fmt.Println("Conn.Read failed,err=",err)
return
}
err=json.Unmarshal(this.Buf[:n],&mes)
if err!=nil{
fmt.Println("json.Unmarshal(mes) failed,err=",err)
return
}
return
}
/*
func (this *Transfer)WritePkg()(mes message.Message) {
buf:=make([]byte,4096)
n,err:=this.Conn.Read(buf)
if err!=nil{
fmt.Println("conn.Read(buf) failed,err=",err)
return
}
err=json.Unmarshal(buf[:n],&mes)
if err!=nil{
fmt.Println("json.Unmarshal failed,err=",err)
return
}
return
}
*/
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yemingzhi/GolangLearnPractice1.git
git@gitee.com:yemingzhi/GolangLearnPractice1.git
yemingzhi
GolangLearnPractice1
golang练习
2bf136849dce

搜索帮助