unwind protobuf *any value
This commit is contained in:
parent
1127b96570
commit
1418d4652e
|
@ -41,7 +41,7 @@ type TreeInfo struct {
|
|||
Disable func(*Node) // disable a widget
|
||||
ShowTable func(*guipb.Table) // attempt at sending a whole table
|
||||
currentTables []*guipb.Table // track the list of tables?
|
||||
Root *guipb.Tree // this is the future of this system
|
||||
// Root *guipb.Tree // this is the future of this system
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
|
|
17
table.go
17
table.go
|
@ -15,6 +15,7 @@ import (
|
|||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
|
||||
func (me *TreeInfo) doTable(a widget.Action) {
|
||||
|
@ -264,7 +265,11 @@ func (me *TreeInfo) addTableRow(t *guipb.Table, grid *Node, name string, w int)
|
|||
me.Add(head)
|
||||
h += 1
|
||||
for _, v := range r.Widgets {
|
||||
v.Name = fmt.Sprintf("%d", v.Size)
|
||||
vi, err := extractInt64(v.Val)
|
||||
if err != nil {
|
||||
log.Log(TREEWARN, "int error", err)
|
||||
}
|
||||
v.Name = fmt.Sprintf("%d", vi)
|
||||
// log.Info("tree: Add()ing to grid here", v.Id, v.Name, w, h)
|
||||
lab := grid.makeGridLabel(v, w, h)
|
||||
me.Add(lab)
|
||||
|
@ -308,6 +313,14 @@ func (me *TreeInfo) addTableRow(t *guipb.Table, grid *Node, name string, w int)
|
|||
return false
|
||||
}
|
||||
|
||||
func extractInt64(anyVal *anypb.Any) (int64, error) {
|
||||
val := &wrapperspb.Int64Value{}
|
||||
if err := anyVal.UnmarshalTo(val); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return val.Value, nil
|
||||
}
|
||||
|
||||
// returns true if widget is in a table
|
||||
func (n *Node) InTable() bool {
|
||||
// log.Info("InTable() parent id =", n.ParentId)
|
||||
|
@ -337,7 +350,7 @@ func dumpTable(t *guipb.Table) {
|
|||
for i, r := range t.IntRows {
|
||||
log.Info("got int row:", t.Title, i, r.Header.Name, r.Vals)
|
||||
for _, v := range r.Widgets {
|
||||
log.Info("tree: got int widget:", v.Id, v.Size)
|
||||
log.Info("tree: got int widget:", v.Id, v.Val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue