You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
812 B
Go

8 years ago
package main
import (
"fmt"
"github.com/golang/protobuf/proto"
)
// datagram represents the top-level envelope in the dota replay format. All
// data in the replay file is packed into datagram frames of at most 65kb.
type dataGram struct {
8 years ago
cmd datagramType
tick int64
body []byte
8 years ago
}
func (g dataGram) String() string {
if len(g.body) > 30 {
8 years ago
return fmt.Sprintf("{dataGram cmd: %v tick: %v size: %d body: %x...}", g.cmd, g.tick, len(g.body), g.body[:27])
8 years ago
}
8 years ago
return fmt.Sprintf("{dataGram cmd: %v tick: %v size: %d body: %x}", g.cmd, g.tick, len(g.body), g.body)
8 years ago
}
func (g *dataGram) Open(m *messageFactory) (proto.Message, error) {
msg, err := m.BuildDatagram(g.cmd)
if err != nil {
return nil, err
8 years ago
}
if err := proto.Unmarshal(g.body, msg); err != nil {
return nil, err
}
return msg, nil
8 years ago
}