Commit 3d4bc65f authored by Kirill Smelkov's avatar Kirill Smelkov

X draft of varable length tracking

parent f596b330
This diff is collapsed.
...@@ -213,6 +213,7 @@ func (d *decoder) emitstrbytes(assignto string) { ...@@ -213,6 +213,7 @@ func (d *decoder) emitstrbytes(assignto string) {
d.emit("if uint32(len(data)) < l { return 0, ErrDecodeOverflow }") d.emit("if uint32(len(data)) < l { return 0, ErrDecodeOverflow }")
d.emit("%v = string(data[:l])", assignto) d.emit("%v = string(data[:l])", assignto)
d.emit("data = data[l:]") d.emit("data = data[l:]")
d.emit("nread += %v + l", d.n)
d.emit("}") d.emit("}")
d.n = 0 d.n = 0
} }
...@@ -223,6 +224,7 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice) ...@@ -223,6 +224,7 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice)
// [len]item // [len]item
d.emit("{ l := %v", d.decodedBasic(nil, types.Typ[types.Uint32])) d.emit("{ l := %v", d.decodedBasic(nil, types.Typ[types.Uint32]))
d.emit("data = data[%v:]", d.n) d.emit("data = data[%v:]", d.n)
d.emit("nread += %v", d.n)
d.n = 0 d.n = 0
d.emit("%v = make(%v, l)", assignto, typeName(typ)) d.emit("%v = make(%v, l)", assignto, typeName(typ))
// TODO size check // TODO size check
...@@ -233,6 +235,7 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice) ...@@ -233,6 +235,7 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice)
// XXX try to avoid (*) in a // XXX try to avoid (*) in a
d.emitobjtype("(*a)", obj, typ.Elem()) // XXX also obj.Elem() ? d.emitobjtype("(*a)", obj, typ.Elem()) // XXX also obj.Elem() ?
d.emit("data = data[%v:]", d.n) // FIXME wrt slice of slice ? d.emit("data = data[%v:]", d.n) // FIXME wrt slice of slice ?
d.emit("nread += %v", d.n)
d.emit("}") d.emit("}")
//d.emit("%v = string(data[:l])", assignto) //d.emit("%v = string(data[:l])", assignto)
d.emit("}") d.emit("}")
...@@ -244,6 +247,7 @@ func (d *decoder) emitmap(assignto string, obj types.Object, typ *types.Map) { ...@@ -244,6 +247,7 @@ func (d *decoder) emitmap(assignto string, obj types.Object, typ *types.Map) {
// [len](key, value) // [len](key, value)
d.emit("{ l := %v", d.decodedBasic(nil, types.Typ[types.Uint32])) d.emit("{ l := %v", d.decodedBasic(nil, types.Typ[types.Uint32]))
d.emit("data = data[%v:]", d.n) d.emit("data = data[%v:]", d.n)
d.emit("nread += %v", d.n)
d.n = 0 d.n = 0
d.emit("%v = make(%v, l)", assignto, typeName(typ)) d.emit("%v = make(%v, l)", assignto, typeName(typ))
// TODO size check // TODO size check
...@@ -267,6 +271,7 @@ func (d *decoder) emitmap(assignto string, obj types.Object, typ *types.Map) { ...@@ -267,6 +271,7 @@ func (d *decoder) emitmap(assignto string, obj types.Object, typ *types.Map) {
} }
d.emit("data = data[%v:]", d.n) // FIXME wrt map of map ? d.emit("data = data[%v:]", d.n) // FIXME wrt map of map ?
d.emit("nread += %v", d.n)
d.emit("}") d.emit("}")
//d.emit("%v = string(data[:l])", assignto) //d.emit("%v = string(data[:l])", assignto)
d.emit("}") d.emit("}")
...@@ -326,6 +331,7 @@ func gendecode(typespec *ast.TypeSpec) string { ...@@ -326,6 +331,7 @@ func gendecode(typespec *ast.TypeSpec) string {
d := decoder{} d := decoder{}
// prologue // prologue
d.emit("func (p *%s) NEODecode(data []byte) (int, error) {", typespec.Name.Name) d.emit("func (p *%s) NEODecode(data []byte) (int, error) {", typespec.Name.Name)
d.emit("var nread uint32")
//n := 0 //n := 0
//t := typespec.Type.(*ast.StructType) // must be //t := typespec.Type.(*ast.StructType) // must be
...@@ -336,7 +342,7 @@ func gendecode(typespec *ast.TypeSpec) string { ...@@ -336,7 +342,7 @@ func gendecode(typespec *ast.TypeSpec) string {
d.emitobjtype("p", obj, typ) d.emitobjtype("p", obj, typ)
d.emit("return %v /* + TODO variable part */, nil", d.n) // FIXME n is wrong after reset d.emit("return int(nread) + %v, nil", d.n)
d.emit("}") d.emit("}")
return d.buf.String() return d.buf.String()
......
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