From 9f58ed0fea4e7b1f8f69846d8f72bec19390d7ed Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 2 Jun 2019 15:38:00 +0200 Subject: [PATCH] ui: add version to OpBlock to track invalidated blocks Signed-off-by: Elias Naur --- ui/internal/ops/ops.go | 2 +- ui/ops.go | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ui/internal/ops/ops.go b/ui/internal/ops/ops.go index cc214b64..d3843a3f 100644 --- a/ui/internal/ops/ops.go +++ b/ui/internal/ops/ops.go @@ -24,7 +24,7 @@ const ( const ( TypeBlockDefLen = 1 + 4 + 4 - TypeBlockLen = 1 + 4 + 4 + TypeBlockLen = 1 + 4 + 4 + 4 TypeTransformLen = 1 + 4*2 TypeLayerLen = 1 TypeRedrawLen = 1 + 8 diff --git a/ui/ops.go b/ui/ops.go index d84e6953..40b84dfa 100644 --- a/ui/ops.go +++ b/ui/ops.go @@ -14,6 +14,7 @@ type Ops struct { } type opsData struct { + version int // Serialized ops. data []byte // Op references. @@ -76,8 +77,9 @@ type OpPush struct{} type OpPop struct{} type OpBlock struct { - ops *Ops - pc pc + ops *Ops + version int + pc pc } type opBlockDef struct { @@ -126,7 +128,7 @@ func (o *Ops) End() OpBlock { bo := binary.LittleEndian bo.PutUint32(data[1:], uint32(pc.data)) bo.PutUint32(data[5:], uint32(pc.refs)) - return OpBlock{ops: o, pc: start} + return OpBlock{ops: o, pc: start, version: o.ops.version} } // Reset clears the Ops. @@ -138,6 +140,7 @@ func (o *Ops) Reset() { func (d *opsData) reset() { d.data = d.data[:0] d.refs = d.refs[:0] + d.version++ } func (d *opsData) write(op []byte, refs []interface{}) { @@ -160,12 +163,14 @@ func (b *OpBlock) decode(data []byte, refs []interface{}) { bo := binary.LittleEndian dataIdx := int(bo.Uint32(data[1:])) refsIdx := int(bo.Uint32(data[5:])) + version := int(bo.Uint32(data[9:])) *b = OpBlock{ ops: refs[0].(*Ops), pc: pc{ data: dataIdx, refs: refsIdx, }, + version: version, } } @@ -175,6 +180,7 @@ func (b OpBlock) Add(o *Ops) { bo := binary.LittleEndian bo.PutUint32(data[1:], uint32(b.pc.data)) bo.PutUint32(data[5:], uint32(b.pc.refs)) + bo.PutUint32(data[9:], uint32(b.version)) o.Write(data, []interface{}{b.ops}) } @@ -212,6 +218,9 @@ func (r *OpsReader) Decode() ([]byte, []interface{}, bool) { if ops.OpType(blockOps.data[op.pc.data]) != ops.TypeBlockDef { panic("invalid block reference") } + if op.version != r.ops.version { + panic("invalid OpBlock reference to reset Ops") + } var opDef opBlockDef opDef.decode(blockOps.data[op.pc.data : op.pc.data+ops.TypeBlockDefLen]) retPC := r.pc