1
0
forked from MTSR/mapserver
mapserver/mapblockparser/mapdata.go

48 lines
825 B
Go
Raw Normal View History

2019-01-06 23:00:24 +03:00
package mapblockparser
import (
"bytes"
2019-01-07 21:38:53 +03:00
"compress/zlib"
"errors"
2019-01-06 23:00:24 +03:00
"io"
"strconv"
)
func parseMapdata(mapblock *MapBlock, data []byte) (int, error) {
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()))
}
2019-01-28 13:45:23 +03:00
rawdata := buf.Bytes()
mapd := MapData{
ContentId: make([]int, 4096),
Param1: make([]int, 4096),
Param2: make([]int, 4096),
}
mapblock.Mapdata = &mapd
for i := 0; i < 4096; i++ {
mapd.ContentId[i] = readU16(rawdata, i*2)
2019-06-19 22:12:04 +03:00
mapd.Param1[i] = readU8(rawdata, (4096*2)+i)
mapd.Param2[i] = readU8(rawdata, (4096*3)+i)
2019-01-28 13:45:23 +03:00
}
2019-01-06 23:00:24 +03:00
return cr.Count, nil
}