emit child types

master
Jordan Orelli 8 years ago
parent 81be585c0d
commit bb40a292e3

@ -12,8 +12,6 @@ import (
"reflect" "reflect"
"runtime/pprof" "runtime/pprof"
"strings" "strings"
"github.com/golang/protobuf/proto"
) )
const ( const (
@ -123,11 +121,15 @@ func main() {
bail(1, "input error: %v", err) bail(1, "input error: %v", err)
} }
c := make(chan proto.Message, 32) c := make(chan maybe, 32)
p := newParser(r) p := newParser(r)
go p.run(c) go p.run(c)
for msg := range c { for m := range c {
fmt.Println(reflect.TypeOf(msg)) if m.error != nil {
fmt.Fprintln(os.Stderr, m.error)
} else {
fmt.Println(reflect.TypeOf(m.Message))
}
} }
if p.err != nil { if p.err != nil {
fmt.Println(err) fmt.Println(err)

@ -7,8 +7,8 @@ import (
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/golang/snappy" "github.com/golang/snappy"
// "github.com/jordanorelli/hyperstone/bit" "github.com/jordanorelli/hyperstone/bit"
// "github.com/jordanorelli/hyperstone/dota" "github.com/jordanorelli/hyperstone/dota"
) )
type parser struct { type parser struct {
@ -28,7 +28,7 @@ func newParser(r io.Reader) *parser {
} }
} }
func (p *parser) run(out chan proto.Message) { func (p *parser) run(out chan maybe) {
defer close(out) defer close(out)
ok, err := p.checkHeader() ok, err := p.checkHeader()
if err != nil { if err != nil {
@ -51,37 +51,44 @@ func (p *parser) run(out chan proto.Message) {
p.err = wrap(err, "open packet error in run loop") p.err = wrap(err, "open packet error in run loop")
return return
} }
out <- msg
switch m := msg.(type) {
case *dota.CDemoPacket:
p.emitChildren(m, out)
}
out <- maybe{Message: msg}
} }
} }
// func (p *parser) emitChildren(pkt *dota.CDemoPacket, c chan maybe) {
// func (p *parser) handleDemoPacket(packet *dota.CDemoPacket) error { br := bit.NewBytesReader(pkt.GetData())
// br := bit.NewBytesReader(packet.GetData()) for {
// for { t := entityType(br.ReadUBitVar())
// t := entityType(br.ReadUBitVar()) s := br.ReadVarInt()
// s := br.ReadVarInt() b := p.scratch[:s]
// b := p.scratch[:s] br.Read(b)
// br.Read(b) p.pbuf.SetBuf(b)
// p.pbuf.SetBuf(b) switch err := br.Err(); err {
// switch err := br.Err(); err { case nil:
// case nil: break
// break case io.EOF:
// case io.EOF: return
// return nil default:
// default: c <- maybe{error: err}
// return err return
// } }
// e, err := messages.BuildEntity(t) e, err := messages.BuildEntity(t)
// if err != nil { if err != nil {
// fmt.Printf("\tskipping entity of size %d, type %s: %v\n", len(b), t, err) c <- maybe{error: wrap(err, "skipping entity of size %d, type %s", len(b), t)}
// continue continue
// } }
// if err := p.pbuf.Unmarshal(e); err != nil { if err := p.pbuf.Unmarshal(e); err != nil {
// fmt.Printf("entity unmarshal error: %v\n", err) c <- maybe{error: wrap(err, "entity unmarshal error")}
// } }
// } c <- maybe{Message: e}
// } }
}
// DecodeVarint reads a varint-encoded integer from the source reader. // DecodeVarint reads a varint-encoded integer from the source reader.
// It returns the value as a uin64 and any errors encountered. The reader will // It returns the value as a uin64 and any errors encountered. The reader will

Loading…
Cancel
Save