// Read the next outer message from the buffer. func (p *Parser) readOuterMessage() (*outerMessage, error) { // Read a command header, which includes both the message type // well as a flag to determine whether or not whether or not the // message is compressed with snappy. command := dota.EDemoCommands(p.reader.readVarUint32()) // Extract the type and compressed flag out of the command msgType := int32(command & ^dota.EDemoCommands_DEM_IsCompressed) msgCompressed := (command & dota.EDemoCommands_DEM_IsCompressed) == dota.EDemoCommands_DEM_IsCompressed // Read the tick that the message corresponds with. tick := p.reader.readVarUint32() // This appears to actually be an int32, where a -1 means pre-game. if tick == 4294967295 { tick = 0 } // Read the size and following buffer. size := int(p.reader.readVarUint32()) buf := p.reader.readBytes(size) // If the buffer is compressed, decompress it with snappy. if msgCompressed { var err error if buf, err = snappy.Decode(nil, buf); err != nil { return nil, err } } // Return the message msg := &outerMessage{ tick: tick, typeId: msgType, data: buf, } return msg, nil }
// readCommand reads a varuint32 as an EDemoCommands func (s *stream) readCommand() (dota.EDemoCommands, error) { c, err := s.readVarUint32() return dota.EDemoCommands(c), err }