all: remove exported Decode methods on operations

Add decode functions to the packages that need them instead. For
TransformOp that is used in multiple packages, add the decode
function to the internal ops package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-08-07 15:52:22 +02:00
parent 4d66669a9e
commit 6e26c92c75
10 changed files with 141 additions and 136 deletions
+24 -4
View File
@@ -3,6 +3,7 @@
package input
import (
"encoding/binary"
"time"
"gioui.org/ui"
@@ -74,15 +75,13 @@ func (q *Router) collect() {
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
switch opconst.OpType(encOp.Data[0]) {
case opconst.TypeInvalidate:
var op ui.InvalidateOp
op.Decode(encOp.Data)
op := decodeInvalidateOp(encOp.Data)
if !q.wakeup || op.At.Before(q.wakeupTime) {
q.wakeup = true
q.wakeupTime = op.At
}
case opconst.TypeProfile:
var op system.ProfileOp
op.Decode(encOp.Data, encOp.Refs)
op := decodeProfileOp(encOp.Data, encOp.Refs)
q.profHandlers = append(q.profHandlers, op.Key)
}
}
@@ -141,3 +140,24 @@ func (h *handlerEvents) Clear() {
delete(h.handlers, k)
}
}
func decodeProfileOp(d []byte, refs []interface{}) system.ProfileOp {
if opconst.OpType(d[0]) != opconst.TypeProfile {
panic("invalid op")
}
return system.ProfileOp{
Key: refs[0].(input.Key),
}
}
func decodeInvalidateOp(d []byte) ui.InvalidateOp {
bo := binary.LittleEndian
if opconst.OpType(d[0]) != opconst.TypeInvalidate {
panic("invalid op")
}
var o ui.InvalidateOp
if nanos := bo.Uint64(d[1:]); nanos > 0 {
o.At = time.Unix(0, int64(nanos))
}
return o
}