Skip to content

Commit

Permalink
feat: partial replay reading for a full player list
Browse files Browse the repository at this point in the history
  • Loading branch information
redraskal committed Feb 2, 2023
1 parent ebacbea commit f122bf8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func main() {
if err != nil {
log.Fatal().Err(err).Send()
}
defer r.Close()
c, err := reader.NewReader(r)
if err != nil {
log.Fatal().Err(err).Send()
Expand Down
33 changes: 22 additions & 11 deletions reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ var ErrInvalidStringSep = errors.New("dissect: invalid string separator")
var strSep = []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

type DissectReader struct {
reader *io.Reader
compressed *zstd.Decoder
offset int
queries [][]byte
listeners []func() error
time int // in seconds
timeRaw string // raw dissect format
Activities []types.Activity `json:"activityFeed"`
Header types.Header `json:"header"`
reader *io.Reader
compressed *zstd.Decoder
offset int
queries [][]byte
listeners []func() error
time int // in seconds
timeRaw string // raw dissect format
partialRead bool // reads up to the player info packets
Activities []types.Activity `json:"activityFeed"`
Header types.Header `json:"header"`
}

// NewReader decompresses in using zstd and
Expand All @@ -34,8 +35,9 @@ func NewReader(in io.Reader) (r *DissectReader, err error) {
return
}
r = &DissectReader{
compressed: compressed,
reader: &in,
compressed: compressed,
reader: &in,
partialRead: false,
}
if err = r.readHeaderMagic(); err != nil {
return
Expand Down Expand Up @@ -72,9 +74,18 @@ func (r *DissectReader) Read() error {
}
}
}
if r.partialRead && len(r.Header.Players) == 10 {
return nil
}
}
}

// PartialRead continues reading the replay past the header until the full player list is read.
func (r *DissectReader) PartialRead() error {
r.partialRead = true
return r.Read()
}

func (r *DissectReader) listen(query []byte, listener func() error) {
r.queries = append(r.queries, query)
r.listeners = append(r.listeners, listener)
Expand Down

0 comments on commit f122bf8

Please sign in to comment.