Commit cdc5f8f4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f076b1b8
...@@ -1456,7 +1456,7 @@ overflow: ...@@ -1456,7 +1456,7 @@ overflow:
// 43. StoreObject // 43. StoreObject
func (p *StoreObject) NEOEncodedLen() int { func (p *StoreObject) NEOEncodedLen() int {
return 58 + len(p.Data)*1 return 58 + len(p.Data)
} }
func (p *StoreObject) NEOEncode(data []byte) { func (p *StoreObject) NEOEncode(data []byte) {
...@@ -1487,11 +1487,8 @@ func (p *StoreObject) NEOEncode(data []byte) { ...@@ -1487,11 +1487,8 @@ func (p *StoreObject) NEOEncode(data []byte) {
l := uint32(len(p.Data)) l := uint32(len(p.Data))
binary.BigEndian.PutUint32(data[37:], l) binary.BigEndian.PutUint32(data[37:], l)
data = data[41:] data = data[41:]
for i := 0; uint32(i) < l; i++ { copy(data, p.Data)
a := &p.Data[i] data = data[l:]
(data[0:])[0] = (*a)
data = data[1:]
}
} }
binary.BigEndian.PutUint64(data[0:], uint64(p.DataSerial)) binary.BigEndian.PutUint64(data[0:], uint64(p.DataSerial))
binary.BigEndian.PutUint64(data[8:], uint64(p.Tid)) binary.BigEndian.PutUint64(data[8:], uint64(p.Tid))
...@@ -1529,17 +1526,13 @@ func (p *StoreObject) NEODecode(data []byte) (int, error) { ...@@ -1529,17 +1526,13 @@ func (p *StoreObject) NEODecode(data []byte) (int, error) {
{ {
l := binary.BigEndian.Uint32(data[37:]) l := binary.BigEndian.Uint32(data[37:])
data = data[41:] data = data[41:]
nread += 41 nread += 41 + l
if uint32(len(data)) < 17+l*1 { if uint32(len(data)) < 17+l {
goto overflow goto overflow
} }
nread += l * 1
p.Data = make([]byte, l) p.Data = make([]byte, l)
for i := 0; uint32(i) < l; i++ { copy(p.Data, data[:l])
a := &p.Data[i] data = data[l:]
(*a) = (data[0:])[0]
data = data[1:]
}
} }
p.DataSerial = Tid(binary.BigEndian.Uint64(data[0:])) p.DataSerial = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = Tid(binary.BigEndian.Uint64(data[8:])) p.Tid = Tid(binary.BigEndian.Uint64(data[8:]))
...@@ -1743,7 +1736,7 @@ overflow: ...@@ -1743,7 +1736,7 @@ overflow:
// 49. AnswerGetObject // 49. AnswerGetObject
func (p *AnswerGetObject) NEOEncodedLen() int { func (p *AnswerGetObject) NEOEncodedLen() int {
return 57 + len(p.Data)*1 return 57 + len(p.Data)
} }
func (p *AnswerGetObject) NEOEncode(data []byte) { func (p *AnswerGetObject) NEOEncode(data []byte) {
...@@ -1775,11 +1768,8 @@ func (p *AnswerGetObject) NEOEncode(data []byte) { ...@@ -1775,11 +1768,8 @@ func (p *AnswerGetObject) NEOEncode(data []byte) {
l := uint32(len(p.Data)) l := uint32(len(p.Data))
binary.BigEndian.PutUint32(data[45:], l) binary.BigEndian.PutUint32(data[45:], l)
data = data[49:] data = data[49:]
for i := 0; uint32(i) < l; i++ { copy(data, p.Data)
a := &p.Data[i] data = data[l:]
(data[0:])[0] = (*a)
data = data[1:]
}
} }
binary.BigEndian.PutUint64(data[0:], uint64(p.DataSerial)) binary.BigEndian.PutUint64(data[0:], uint64(p.DataSerial))
} }
...@@ -1816,17 +1806,13 @@ func (p *AnswerGetObject) NEODecode(data []byte) (int, error) { ...@@ -1816,17 +1806,13 @@ func (p *AnswerGetObject) NEODecode(data []byte) (int, error) {
{ {
l := binary.BigEndian.Uint32(data[45:]) l := binary.BigEndian.Uint32(data[45:])
data = data[49:] data = data[49:]
nread += 49 nread += 49 + l
if uint32(len(data)) < 8+l*1 { if uint32(len(data)) < 8+l {
goto overflow goto overflow
} }
nread += l * 1
p.Data = make([]byte, l) p.Data = make([]byte, l)
for i := 0; uint32(i) < l; i++ { copy(p.Data, data[:l])
a := &p.Data[i] data = data[l:]
(*a) = (data[0:])[0]
data = data[1:]
}
} }
p.DataSerial = Tid(binary.BigEndian.Uint64(data[0:])) p.DataSerial = Tid(binary.BigEndian.Uint64(data[0:]))
return 8 + int(nread), nil return 8 + int(nread), nil
......
...@@ -222,8 +222,8 @@ type CodecCodeGen interface { ...@@ -222,8 +222,8 @@ type CodecCodeGen interface {
genSlice(path string, typ *types.Slice, obj types.Object) genSlice(path string, typ *types.Slice, obj types.Object)
genMap(path string, typ *types.Map, obj types.Object) genMap(path string, typ *types.Map, obj types.Object)
// XXX particular case of slice // particular case of slice or array with 1-byte elem
genStrBytes(path string) genSlice1(path string, typ types.Type)
// get generated code. // get generated code.
// for top-level functions this is whole function including return and closing } // for top-level functions this is whole function including return and closing }
...@@ -514,12 +514,12 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ ...@@ -514,12 +514,12 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ
// len u32 // len u32
// [len]byte // [len]byte
// TODO []byte support // TODO []byte support
func (s *sizer) genStrBytes(path string) { func (s *sizer) genSlice1(path string, typ types.Type) {
s.size.Add(4) s.size.Add(4)
s.size.AddExpr("len(%s)", path) s.size.AddExpr("len(%s)", path)
} }
func (e *encoder) genStrBytes(path string) { func (e *encoder) genSlice1(path string, typ types.Type) {
e.emit("{") e.emit("{")
e.emit("l := uint32(len(%s))", path) e.emit("l := uint32(len(%s))", path)
e.genBasic("l", types.Typ[types.Uint32], nil) e.genBasic("l", types.Typ[types.Uint32], nil)
...@@ -530,7 +530,7 @@ func (e *encoder) genStrBytes(path string) { ...@@ -530,7 +530,7 @@ func (e *encoder) genStrBytes(path string) {
e.n = 0 e.n = 0
} }
func (d *decoder) genStrBytes(assignto string) { func (d *decoder) genSlice1(assignto string, typ types.Type) {
d.emit("{") d.emit("{")
d.genBasic("l:", types.Typ[types.Uint32], nil) d.genBasic("l:", types.Typ[types.Uint32], nil)
...@@ -541,7 +541,22 @@ func (d *decoder) genStrBytes(assignto string) { ...@@ -541,7 +541,22 @@ func (d *decoder) genStrBytes(assignto string) {
d.overflowCheckpoint() d.overflowCheckpoint()
d.overflowCheckSize.AddExpr("l") d.overflowCheckSize.AddExpr("l")
d.emit("%v= string(data[:l])", assignto) switch t := typ.(type) {
case *types.Basic:
if t.Kind() != types.String {
log.Panicf("bad basic type in slice1: %v", t)
}
d.emit("%v= string(data[:l])", assignto)
case *types.Slice:
// TODO not copy, but reference data from original
d.emit("%v= make(%v, l)", assignto, typeName(typ))
d.emit("copy(%v, data[:l])", assignto)
default:
log.Panicf("bad type in slice1: %v", typ)
}
d.emit("data = data[l:]") d.emit("data = data[l:]")
d.emit("}") d.emit("}")
} }
...@@ -776,7 +791,7 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodecCod ...@@ -776,7 +791,7 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodecCod
switch u := typ.Underlying().(type) { switch u := typ.Underlying().(type) {
case *types.Basic: case *types.Basic:
if u.Kind() == types.String { if u.Kind() == types.String {
codegen.genStrBytes(path) codegen.genSlice1(path, u)
break break
} }
...@@ -793,14 +808,24 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodecCod ...@@ -793,14 +808,24 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodecCod
} }
case *types.Array: case *types.Array:
// TODO optimize for [...]byte elemSize, _ := typeSizeFixed(u.Elem())
var i int64 // XXX because `u.Len() int64` // [...]byte or [...]uint8 - just straight copy
for i = 0; i < u.Len(); i++ { if false && elemSize == 1 {
codegenType(fmt.Sprintf("%v[%v]", path, i), u.Elem(), obj, codegen) //codegen.genStrBytes(path+"[:]") // FIXME
codegen.genSlice1(path, u) // FIXME
} else {
var i int64 // XXX because `u.Len() int64`
for i = 0; i < u.Len(); i++ {
codegenType(fmt.Sprintf("%v[%v]", path, i), u.Elem(), obj, codegen)
}
} }
case *types.Slice: case *types.Slice:
codegen.genSlice(path, u, obj) if elemSize, _ := typeSizeFixed(u.Elem()); elemSize == 1 {
codegen.genSlice1(path, u)
} else {
codegen.genSlice(path, u, obj)
}
case *types.Map: case *types.Map:
codegen.genMap(path, u, obj) codegen.genMap(path, u, obj)
......
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