there's an envelope missing

manta looks like it's parsing an envelope type manually instead of
defining a proto definition for it. next step is to try to synthesize
that definition based on the manta code. it appears to be as follows:

message Envelope {
    required EDemoCommands command = 1;
    required varint tick = 2;
    required varint size = 3;
    required bytes body = 4;
}

or something to that effect. Reading protobuf primitives off the wire
manually is looney-bins.
master
Jordan Orelli 8 years ago
parent 8c53711fbe
commit e590c52e8b

@ -69,7 +69,7 @@ func main() {
}
p := newParser(r)
if _, err := p.checkHeader(); err != nil {
if err := p.start(); err != nil {
bail(1, "parse error: %v", err)
}
}

@ -8,17 +8,39 @@ import (
type parser struct {
// the source of replay bytes. Must NOT be compressed.
source io.Reader
// re-useable scratch buffer. Contents never guaranteed to be clean.
scratch []byte
}
func newParser(r io.Reader) *parser {
return &parser{source: r}
return &parser{source: r, scratch: make([]byte, 1<<10)}
}
func (p *parser) start() error {
ok, err := p.checkHeader()
if err != nil {
return fmt.Errorf("parser start error: %v", err)
}
if !ok {
return fmt.Errorf("parser start error: invalid header")
}
return nil
}
// checks whether we have an acceptable header at the current reader position.
func (p *parser) checkHeader() (bool, error) {
buf := make([]byte, 8)
buf := p.scratch[:8]
if _, err := p.source.Read(buf); err != nil {
return false, fmt.Errorf("unable to read header bytes: %v", err)
}
return string(buf) == replay_header, nil
}
// skips n bytes in the underlying source
func (p *parser) skip(n int) error {
if _, err := p.source.Read(p.scratch[:n]); err != nil {
return fmt.Errorf("unable to skip %d bytes: %v", n, err)
}
return nil
}

Loading…
Cancel
Save