Commit 02ec3a41 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 395e91bb
...@@ -304,3 +304,18 @@ func (p *AnswerUnfinishedTransactions) NEODecode(data []byte) (int, error) { ...@@ -304,3 +304,18 @@ func (p *AnswerUnfinishedTransactions) NEODecode(data []byte) (int, error) {
func (p *LockedTransactions) NEODecode(data []byte) (int, error) { func (p *LockedTransactions) NEODecode(data []byte) (int, error) {
return 0 /* + TODO variable part */, nil return 0 /* + TODO variable part */, nil
} }
func (p *AnswerLockedTransactions) NEODecode(data []byte) (int, error) {
{
l := BigEndian.Uint32(data[0:])
data = data[4:]
p.TidDict = make(map[neo.Tid]neo.Tid, l)
m := p.TidDict
for i := 0; i < l; i++ {
key = BigEndian.Uint64(data[0:])
m[key] = BigEndian.Uint64(data[8:])
data = data[16:]
}
}
return 0 /* + TODO variable part */, nil
}
...@@ -327,12 +327,12 @@ type AnswerUnfinishedTransactions struct { ...@@ -327,12 +327,12 @@ type AnswerUnfinishedTransactions struct {
// Answer locked transactions S -> PM. // Answer locked transactions S -> PM.
type LockedTransactions struct { type LockedTransactions struct {
} }
/*
type AnswerLockedTransactions struct { type AnswerLockedTransactions struct {
TidDict map[Tid]Tid // ttid -> tid TidDict map[Tid]Tid // ttid -> tid
} }
/*
// Return final tid if ttid has been committed. * -> S. C -> PM. // Return final tid if ttid has been committed. * -> S. C -> PM.
type FinalTID struct { type FinalTID struct {
TTID Tid TTID Tid
......
...@@ -209,13 +209,13 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice) ...@@ -209,13 +209,13 @@ 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.n = 0
d.emit("%v = make(%v, l)", assignto, typ) d.emit("%v = make(%v, l)", assignto, typ)
// TODO size check // TODO size check
// TODO if size(item)==const - check l in one go // TODO if size(item)==const - check l in one go
//d.emit("if len(data) < l { return 0, ErrDecodeOverflow }") //d.emit("if len(data) < l { return 0, ErrDecodeOverflow }")
d.emit("for i := 0; i < l; i++ {") d.emit("for i := 0; i < l; i++ {")
d.emit("a := &%s[i]", assignto) d.emit("a := &%s[i]", assignto)
d.n = 0
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("}") d.emit("}")
...@@ -224,6 +224,27 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice) ...@@ -224,6 +224,27 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice)
d.n = 0 d.n = 0
} }
func (d *decoder) emitmap(assignto string, obj types.Object, typ *types.Map) {
// len u32
// [len](key, value)
d.emit("{ l := %v", d.decodedBasic(nil, types.Typ[types.Uint32]))
d.emit("data = data[%v:]", d.n)
d.n = 0
d.emit("%v = make(%v, l)", assignto, typ)
// TODO size check
// TODO if size(item)==const - check l in one go
//d.emit("if len(data) < l { return 0, ErrDecodeOverflow }")
d.emit("m := %v", assignto)
d.emit("for i := 0; i < l; i++ {")
d.emitobjtype("key", obj, typ.Key()) // TODO -> :=
d.emitobjtype("m[key]", obj, typ.Elem())
d.emit("data = data[%v:]", d.n) // FIXME wrt map of map ?
d.emit("}")
//d.emit("%v = string(data[:l])", assignto)
d.emit("}")
d.n = 0
}
// top-level driver for emitting decode code for obj/type // top-level driver for emitting decode code for obj/type
func (d *decoder) emitobjtype(assignto string, obj types.Object, typ types.Type) { func (d *decoder) emitobjtype(assignto string, obj types.Object, typ types.Type) {
switch u := typ.Underlying().(type) { switch u := typ.Underlying().(type) {
...@@ -238,8 +259,8 @@ func (d *decoder) emitobjtype(assignto string, obj types.Object, typ types.Type) ...@@ -238,8 +259,8 @@ func (d *decoder) emitobjtype(assignto string, obj types.Object, typ types.Type)
case *types.Slice: case *types.Slice:
d.emitslice(assignto, obj, u) d.emitslice(assignto, obj, u)
//case *types.Map: case *types.Map:
// // TODO d.emitmap(assignto, obj, u)
case *types.Struct: case *types.Struct:
......
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