Commit f24296e3 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 2d7a1229
...@@ -170,10 +170,7 @@ overflow: ...@@ -170,10 +170,7 @@ overflow:
func (p *XXXTest) NEOEncodedLen() int { func (p *XXXTest) NEOEncodedLen() int {
var size int var size int
for key := range p.Zzz { for key := range p.Zzz {
for key := range p.Zzz[key] { size += len(p.Zzz[key])
size += len(p.Zzz[key][key])
}
size += len(p.Zzz[key]) * 8
} }
return 12 + len(p.Zzz)*8 + size return 12 + len(p.Zzz)*8 + size
} }
...@@ -196,22 +193,8 @@ func (p *XXXTest) NEOEncode(data []byte) { ...@@ -196,22 +193,8 @@ func (p *XXXTest) NEOEncode(data []byte) {
l := uint32(len(p.Zzz[key])) l := uint32(len(p.Zzz[key]))
binary.BigEndian.PutUint32(data[4:], l) binary.BigEndian.PutUint32(data[4:], l)
data = data[8:] data = data[8:]
keyv := make([]int32, 0, l) copy(data, p.Zzz[key])
for key := range p.Zzz[key] { data = data[l:]
keyv = append(keyv, key)
}
sort.Slice(keyv, func(i, j int) bool { return keyv[i] < keyv[j] })
for _, key := range keyv {
binary.BigEndian.PutUint32(data[0:], uint32(key))
{
l := uint32(len(p.Zzz[key][key]))
binary.BigEndian.PutUint32(data[4:], l)
data = data[8:]
copy(data, p.Zzz[key][key])
data = data[l:]
}
data = data[0:]
}
} }
data = data[0:] data = data[0:]
} }
...@@ -229,38 +212,23 @@ func (p *XXXTest) NEODecode(data []byte) (int, error) { ...@@ -229,38 +212,23 @@ func (p *XXXTest) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[8:]) l := binary.BigEndian.Uint32(data[8:])
data = data[12:] data = data[12:]
nread += 12 nread += 12
p.Zzz = make(map[int32]map[int32]string, l) p.Zzz = make(map[int32]string, l)
m := p.Zzz m := p.Zzz
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
if uint32(len(data)) < 8 { if uint32(len(data)) < 8 {
goto overflow goto overflow
} }
key := int32(binary.BigEndian.Uint32(data[0:])) key := int32(binary.BigEndian.Uint32(data[0:]))
var v map[int32]string
{ {
l := binary.BigEndian.Uint32(data[4:]) l := binary.BigEndian.Uint32(data[4:])
data = data[8:] data = data[8:]
nread += 8 nread += 8 + l
v = make(map[int32]string, l) if uint32(len(data)) < l {
m := v goto overflow
for i := 0; uint32(i) < l; i++ {
if uint32(len(data)) < 8 {
goto overflow
}
key := int32(binary.BigEndian.Uint32(data[0:]))
{
l := binary.BigEndian.Uint32(data[4:])
data = data[8:]
nread += 8 + l
if uint32(len(data)) < l {
goto overflow
}
m[key] = string(data[:l])
data = data[l:]
}
} }
m[key] = string(data[:l])
data = data[l:]
} }
m[key] = v
} }
} }
return 0 + int(nread), nil return 0 + int(nread), nil
......
...@@ -198,7 +198,7 @@ type RowInfo struct { ...@@ -198,7 +198,7 @@ type RowInfo struct {
type XXXTest struct { type XXXTest struct {
qqq uint32 qqq uint32
aaa uint32 aaa uint32
Zzz map[int32]map[int32]string Zzz map[int32]string
} }
......
...@@ -745,7 +745,6 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) { ...@@ -745,7 +745,6 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) {
codegenType(fmt.Sprintf("%s[key]", path), typ.Elem(), obj, e) codegenType(fmt.Sprintf("%s[key]", path), typ.Elem(), obj, e)
e.emit("data = data[%v:]", e.n) // XXX wrt map of map? e.emit("data = data[%v:]", e.n) // XXX wrt map of map?
e.emit("}") e.emit("}")
// XXX vvv ?
e.emit("}") e.emit("}")
e.n = 0 e.n = 0
} }
...@@ -782,7 +781,6 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) { ...@@ -782,7 +781,6 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
switch typ.Elem().Underlying().(type) { switch typ.Elem().Underlying().(type) {
// basic types can be directly assigned to map entry // basic types can be directly assigned to map entry
case *types.Basic: case *types.Basic:
// XXX handle string
codegenType("m[key]", typ.Elem(), obj, d) codegenType("m[key]", typ.Elem(), obj, d)
// otherwise assign via temporary // otherwise assign via temporary
...@@ -795,7 +793,7 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) { ...@@ -795,7 +793,7 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
// d.resetPos() with nread update optionally skipped // d.resetPos() with nread update optionally skipped
if d.n != 0 { if d.n != 0 {
d.emit("data = data[%v:]", d.n) d.emit("data = data[%v:]", d.n)
if !elemFixed { if !itemFixed {
d.emit("%v += %v", d.var_("nread"), d.n) d.emit("%v += %v", d.var_("nread"), d.n)
} }
d.n = 0 d.n = 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment