strings kinda work as 'any' now

This commit is contained in:
Jeff Carr 2025-09-16 09:53:05 -05:00
parent eb17a09114
commit 7d2c654cec
1 changed files with 38 additions and 6 deletions

View File

@ -389,15 +389,47 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " // r.Attr.Width = int32(sf.Width)")
fmt.Fprintln(w, " // r.Attr.Type = guipb.ColAttr_TIME")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " for m := range mt.x.IterAll() {")
fmt.Fprintln(w, " t := sf.f(m)")
fmt.Fprintln(w, " var goTime time.Time")
fmt.Fprintln(w, " goTime = t.(time.Time)")
fmt.Fprintln(w, " tsProto := timestamppb.New(goTime)")
fmt.Fprintln(w, " anyProto, err := anypb.New(tsProto)")
fmt.Fprintln(w, " _ = err // do something with err someday (?)")
fmt.Fprintln(w, " r.Vals = append(r.Vals, anyProto)")
fmt.Fprintln(w, " switch r.Attr.Type {")
fmt.Fprintln(w, " case guipb.ColAttr_STRING:")
fmt.Fprintln(w, " // anyProto, err := anypb.New(tsProto)")
fmt.Fprintln(w, " stringValue := wrapperspb.String(t.(string))")
fmt.Fprintln(w, " anyProto, err := anypb.New(stringValue)")
fmt.Fprintln(w, " _ = err // do something with err someday (?)")
fmt.Fprintln(w, " r.Vals = append(r.Vals, anyProto)")
fmt.Fprintln(w, " // return col.Vals[row] true")
fmt.Fprintln(w, " case guipb.ColAttr_INT:")
fmt.Fprintln(w, " // var finalInt int32")
fmt.Fprintln(w, " // // 1. Check if the Any contains an Int32Value")
fmt.Fprintln(w, " // if anyVal.MessageIs(&wrapperspb.Int32Value{}) {")
fmt.Fprintln(w, " // var intValue wrapperspb.Int32Value")
fmt.Fprintln(w, " // // 2. Unmarshal into the wrapper")
fmt.Fprintln(w, " // if err := anyVal.UnmarshalTo(&intValue); err == nil {")
fmt.Fprintln(w, " // // 3. Get the native Go int32 from the wrapper")
fmt.Fprintln(w, " // finalInt = intValue.GetValue()")
fmt.Fprintln(w, " // }")
fmt.Fprintln(w, " // }")
fmt.Fprintln(w, "")
sfmt := "\"" + "%" + "d" + "\""
fmt.Fprintln(w, " // return fmt.Sprintf("+sfmt+", finalInt), true")
fmt.Fprintln(w, " case guipb.ColAttr_DURATION:")
fmt.Fprintln(w, " case guipb.ColAttr_TIME:")
fmt.Fprintln(w, " var goTime time.Time")
fmt.Fprintln(w, " goTime = t.(time.Time)")
fmt.Fprintln(w, " tsProto := timestamppb.New(goTime)")
fmt.Fprintln(w, " anyProto, err := anypb.New(tsProto)")
fmt.Fprintln(w, " _ = err // do something with err someday (?)")
fmt.Fprintln(w, " r.Vals = append(r.Vals, anyProto)")
fmt.Fprintln(w, " default:")
fmt.Fprintln(w, " log.Info(\"cell unhandled type\", r.Attr.Type)")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " // cellTime := r.Vals[row]")
fmt.Fprintln(w, " // s := shell.FormatDuration(time.Since(cellTime.AsTime()))")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " mt.pb.AnyCols = append(mt.pb.AnyCols, r)")
fmt.Fprintln(w, " return true")
fmt.Fprintln(w, " }")