forked from MTSR/mapserver
parse test
This commit is contained in:
parent
9afcfed658
commit
904cb3496d
@ -11,17 +11,17 @@ type MapBlock struct {
|
|||||||
|
|
||||||
type Metadata struct {
|
type Metadata struct {
|
||||||
Inventories map[int]map[string]*Inventory
|
Inventories map[int]map[string]*Inventory
|
||||||
Pairs map[int]map[string]*string
|
Pairs map[int]map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *Metadata) GetPairsMap(pos int) map[string]*string {
|
func (md *Metadata) GetPairsMap(pos int) map[string]string {
|
||||||
if md.Pairs == nil {
|
if md.Pairs == nil {
|
||||||
md.Pairs = make(map[int]map[string]*string)
|
md.Pairs = make(map[int]map[string]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
pairsMap := md.Pairs[pos]
|
pairsMap := md.Pairs[pos]
|
||||||
if pairsMap == nil {
|
if pairsMap == nil {
|
||||||
pairsMap = make(map[string]*string)
|
pairsMap = make(map[string]string)
|
||||||
md.Pairs[pos] = pairsMap
|
md.Pairs[pos] = pairsMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,10 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) {
|
|||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
io.Copy(buf, z)
|
io.Copy(buf, z)
|
||||||
|
|
||||||
|
if cr.Count == 0 {
|
||||||
|
return 0, errors.New("no data")
|
||||||
|
}
|
||||||
|
|
||||||
metadata := buf.Bytes()
|
metadata := buf.Bytes()
|
||||||
|
|
||||||
offset := 0
|
offset := 0
|
||||||
@ -86,17 +90,14 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) {
|
|||||||
offset+=keyLength
|
offset+=keyLength
|
||||||
|
|
||||||
valueLength := readU32(metadata, offset)
|
valueLength := readU32(metadata, offset)
|
||||||
offset+=4;
|
offset+=4
|
||||||
|
|
||||||
value := string(metadata[offset:keyLength+offset])
|
value := string(metadata[offset:valueLength+offset])
|
||||||
offset+=valueLength
|
offset+=valueLength
|
||||||
|
|
||||||
pairsMap[key] = &value
|
pairsMap[key] = value
|
||||||
|
|
||||||
offset++
|
offset++
|
||||||
|
|
||||||
log.Println("MD item", i, offset, position, valuecount, valueLength, keyLength, pairsMap)//XXX
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentInventoryName *string = nil
|
var currentInventoryName *string = nil
|
||||||
@ -108,7 +109,7 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) {
|
|||||||
txt := scanner.Text()
|
txt := scanner.Text()
|
||||||
offset += len(txt) + 1;
|
offset += len(txt) + 1;
|
||||||
|
|
||||||
log.Println("inv", txt)
|
log.Println("inv", txt)//XXX
|
||||||
|
|
||||||
if txt == INVENTORY_END {
|
if txt == INVENTORY_END {
|
||||||
currentInventoryName = nil
|
currentInventoryName = nil
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package mapblockparser
|
package mapblockparser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -40,6 +41,7 @@ func TestParse(t *testing.T){
|
|||||||
}
|
}
|
||||||
|
|
||||||
mapblock, err := Parse(data)
|
mapblock, err := Parse(data)
|
||||||
|
fmt.Println("mapblock.Metadata", mapblock.Metadata)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@ -56,4 +58,26 @@ func TestParse(t *testing.T){
|
|||||||
if len(mapblock.Mapdata) != 16384 {
|
if len(mapblock.Mapdata) != 16384 {
|
||||||
t.Error("Mapdata length wrong")
|
t.Error("Mapdata length wrong")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pairs := mapblock.Metadata.GetPairsMap(0)
|
||||||
|
if pairs["owner"] != "pipo" {
|
||||||
|
t.Error(pairs["owner"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func TestParse2(t *testing.T){
|
||||||
|
log.SetLevel(log.DebugLevel)
|
||||||
|
|
||||||
|
data, err := ioutil.ReadFile("testdata/0.9.0")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = Parse(data)
|
||||||
|
//fmt.Println("mapblock.Metadata", mapblock.Metadata)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user