Commit 541e343f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 86c21792
......@@ -35,3 +35,17 @@ func (p *CellInfo) NEODecode(data []byte) (int, error) {
p.CellState = int32(BigEndian.Uint32(data[4:]))
return 8 /* + TODO variable part */, nil
}
func (p *RowInfo) NEODecode(data []byte) (int, error) {
p.Offset = BigEndian.Uint32(data[0:])
{
l := BigEndian.Uint32(data[4:])
data = data[8:]
p.CellList = make([]neo.CellInfo, l)
for i := 0; i < l; i++ {
p.CellList[i].UUID = int32(BigEndian.Uint32(data[0:]))
p.CellList[i].CellState = int32(BigEndian.Uint32(data[4:]))
data = data[8:]
}
}
return 0 /* + TODO variable part */, nil
}
......@@ -169,7 +169,6 @@ type CellInfo struct {
CellState
}
/*
//type RowList []struct {
type RowInfo struct {
Offset uint32 // PNumber
......@@ -178,6 +177,7 @@ type RowInfo struct {
/*
// // XXX link request <-> answer ?
// // XXX naming -> PktHeader ?
// type PktHead struct {
......
......@@ -203,6 +203,24 @@ func (d *decoder) emitstrbytes(assignto string) {
d.n = 0
}
func (d *decoder) emitslice(assignto string, obj types.Object, typ *types.Slice) {
// len u32
// [len]item
d.emit("{ l := %v", d.decodedBasic(nil, types.Typ[types.Uint32]))
d.emit("data = data[%v:]", d.n)
d.emit("%v = make(%v, l)", assignto, typ)
// 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.n = 0
d.emitobjtype(assignto + "[i]", obj, typ.Elem()) // XXX also obj.Elem() ?
d.emit("data = data[%v:]", d.n) // FIXME wrt slice of slice ?
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) {
......@@ -214,8 +232,8 @@ func (d *decoder) emitobjtype(assignto string, obj types.Object, typ types.Type)
d.emit("%s = %s", assignto, d.decodedBasic(obj, u))
//case *types.Slice:
// // TODO
case *types.Slice:
d.emitslice(assignto, obj, u)
//case *types.Map:
// // TODO
......
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