单个peer的文件下载实现

This commit is contained in:
liwei committed 2019-10-08 16:56:22 +08:00
1 parent fe0138440f
commit 15a4b6ddc4
9 files changed
+179 -48

No files matched your search

+2 -2
View File
@@ -29,14 +29,14 @@ type Message struct {
ID ID
}
func (msg Message) Encode() []byte {
func (msg *Message) Encode() []byte {
buf := make([]byte, 5)
binary.BigEndian.PutUint32(buf, msg.Length)
buf[4] = byte(msg.ID)
return buf
}
func (msg Message) Decode(buf []byte) {
func (msg *Message) Decode(buf []byte) {
msg.Length = binary.BigEndian.Uint32(buf)
msg.ID = ID(buf[4])
}