From a18553a3ec8d4621c1d41f3d9bdeb8000ea81e20 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Fri, 5 Aug 2016 19:51:27 -0400 Subject: [PATCH] oh this is definitely important --- packet.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 packet.go diff --git a/packet.go b/packet.go new file mode 100644 index 0000000..d60d7f4 --- /dev/null +++ b/packet.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + + "github.com/golang/protobuf/proto" +) + +// packet represents the top-level envelope in the dota replay format. All +// data in the replay file is packed into packets of at most 65kb. +type packet struct { + cmd packetType + tick int64 + body []byte +} + +func (p packet) String() string { + if len(p.body) > 30 { + return fmt.Sprintf("{packet cmd: %v tick: %v size: %d body: %x...}", p.cmd, p.tick, len(p.body), p.body[:27]) + } + return fmt.Sprintf("{packet cmd: %v tick: %v size: %d body: %x}", p.cmd, p.tick, len(p.body), p.body) +} + +func (p *packet) Open(m *messageFactory, pbuf *proto.Buffer) (proto.Message, error) { + msg, err := m.BuildPacket(p.cmd) + if err != nil { + return nil, err + } + pbuf.SetBuf(p.body) + if err := pbuf.Unmarshal(msg); err != nil { + return nil, err + } + return msg, nil +}