1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-07-01 16:10:24 +08:00
This commit is contained in:
fumiama
2021-10-24 20:29:44 +08:00
parent 8b6e74f756
commit fa1608165b
9 changed files with 158 additions and 100 deletions

View File

@@ -1,5 +1,7 @@
package head
import "encoding/json"
type Packet struct {
DataSZ uint32
Proto uint8
@@ -21,10 +23,13 @@ func NewPacket(proto uint8, srcPort uint16, dstPort uint16, data []byte) *Packet
}
}
func (p *Packet) UnMashal(data []byte) {
func (p *Packet) UnMashal(data []byte) error {
return json.Unmarshal(data, p)
}
func (p *Packet) Mashal(src string, dst string) []byte {
return nil
func (p *Packet) Mashal(src string, dst string) ([]byte, error) {
p.DataSZ = uint32(len(p.Data))
p.Src = src
p.Dst = dst
return json.Marshal(p)
}