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

.

parent 395e91bb
......@@ -304,3 +304,18 @@ func (p *AnswerUnfinishedTransactions) NEODecode(data []byte) (int, error) {
func (p *LockedTransactions) NEODecode(data []byte) (int, error) {
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 {
// Answer locked transactions S -> PM.
type LockedTransactions struct {
}
/*
type AnswerLockedTransactions struct {
TidDict map[Tid]Tid // ttid -> tid
}
/*
// Return final tid if ttid has been committed. * -> S. C -> PM.
type FinalTID struct {
TTID Tid
......
......@@ -209,13 +209,13 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice)
// [len]item
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("for i := 0; i < l; i++ {")
d.emit("a := &%s[i]", assignto)
d.n = 0
d.emitobjtype("a", obj, typ.Elem()) // XXX also obj.Elem() ?
d.emit("data = data[%v:]", d.n) // FIXME wrt slice of slice ?
d.emit("}")
......@@ -224,6 +224,27 @@ func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice)
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
func (d *decoder) emitobjtype(assignto string, obj types.Object, typ types.Type) {
switch u := typ.Underlying().(type) {
......@@ -238,8 +259,8 @@ func (d *decoder) emitobjtype(assignto string, obj types.Object, typ types.Type)
case *types.Slice:
d.emitslice(assignto, obj, u)
//case *types.Map:
// // TODO
case *types.Map:
d.emitmap(assignto, obj, u)
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