43 lines
679 B
Go
Raw Normal View History

2019-01-06 21:00:24 +01:00
package mapblockparser
import (
"errors"
"compress/zlib"
"bytes"
"io"
"strconv"
log "github.com/sirupsen/logrus"
)
//TODO: mapdata struct with accessors
func parseMapdata(mapblock *MapBlock, data []byte) (int, error) {
log.WithFields(log.Fields{
"data-length": len(data),
}).Debug("Parsing map-data")
r := bytes.NewReader(data)
cr := new(CountedReader)
cr.Reader = r
z, err := zlib.NewReader(cr)
if err != nil {
return 0, err
}
defer z.Close()
buf := new(bytes.Buffer)
io.Copy(buf, z)
if buf.Len() != 16384 {
return 0, errors.New("Mapdata length invalid: " + strconv.Itoa(buf.Len()))
}
mapblock.Mapdata = buf.Bytes()
return cr.Count, nil
}