adding more table pb options

This commit is contained in:
Jeff Carr 2025-03-10 13:52:04 -05:00
parent a496b7abf7
commit 63a3d0dc24
4 changed files with 93 additions and 18 deletions

View File

@ -21,8 +21,8 @@ message Apple {
google.protobuf.Timestamp ctime = 3; // when the apple was born
}
message Apples {
string name = 1; // `autogenpb:unique` // generates SortByxxx() and AppendUnique() functions
message Apples { // `autogenpb:gui:Apple`
string name = 1; // `autogenpb:unique`
string genus = 2; // `autogenpb:unique` // generates same thing here but SortByGenus()
repeated Apple apples = 3;
}

View File

@ -46,6 +46,8 @@ message MsgName {
bool needIter = 10; // true if the sort iterator has not been generated yet
bool needAll = 11; // true if the sort iterator has not been generated yet
bool noMutex = 12; // only use the global mutex
bool doGui = 13; // if a gui.pb.go file should be created
string guiVarName = 14; // the name of the variable to use
}
message Sort {

View File

@ -32,22 +32,82 @@ func (pb *Files) makeGuiFile(pf *File) error {
fmt.Fprintf(newf, "// START GUI\n")
fmt.Fprintf(newf, "\n")
guiMain(newf, pf.Bases.Name, pf.Base.Name)
guiStringFuncs(newf, pf.Package, pf.Bases.Name, pf.Base.Name)
/*
FRUITS := pf.Bases.Name
FRUIT := pf.Base.Name
fruitVars := pf.Base.Vars
pf.generateAutoTablePB(newf, FRUITS, FRUIT, fruitVars)
*/
for _, v := range pf.Base.Vars {
for _, msg := range pf.allMsg() {
if msg.DoGui {
color := pf.findMsg(msg.GuiVarName)
if color == nil {
return fmt.Errorf("failed to find struct %s", msg.GuiVarName)
}
FRUITS := msg.Name
FRUIT := msg.GuiVarName
fruitVars := color.Vars
pf.generateAutoTablePB(newf, FRUITS, FRUIT, fruitVars)
log.Printf("NEED TO ADD GUI FOR %s with var %s and found msg struct %s\n", msg.Name, msg.GuiVarName, color.Lockname)
}
}
// os.Exit(-1)
/*
guiMain(newf, pf.Bases.Name, pf.Base.Name)
guiStringFuncs(newf, pf.Package, pf.Bases.Name, pf.Base.Name)
for _, v := range pf.Base.Vars {
if v.IsRepeated {
// can't work against slices
continue
}
if v.VarType == "string" {
log.Printf("make Add function here %s %s %s\n", pf.Bases.Name, pf.Base.Name, v.VarName)
guiAddStringFunc(newf, pf.Bases.Name, pf.Base.Name, v.VarName)
continue
}
if v.VarType == "int64" {
log.Printf("make Add function here %s %s %s\n", pf.Bases.Name, pf.Base.Name, v.VarName)
guiAddIntFunc(newf, pf.Bases.Name, pf.Base.Name, v.VarName)
continue
}
}
FRUITS := pf.Bases.Name
FRUIT := pf.Base.Name
fRUITS := untitle(pf.Bases.Name)
fRUIT := untitle(pf.Base.Name)
guiUpdate(newf, FRUITS, FRUIT)
guiTableDelete(newf, FRUITS, FRUIT)
guiTableCustom(newf, FRUITS, fRUITS, FRUIT, fRUIT)
*/
fmt.Fprintf(newf, "\n")
fmt.Fprintf(newf, "// END GUI\n")
return nil
}
func (pf *File) generateAutoTablePB(newf *os.File, FRUITS string, FRUIT string, fruitVars []*MsgVar) {
fRUITS := untitle(FRUITS)
fRUIT := untitle(FRUIT)
guiMain(newf, FRUITS, FRUIT)
guiStringFuncs(newf, pf.Package, FRUITS, FRUIT)
for _, v := range fruitVars {
if v.IsRepeated {
// can't work against slices
continue
}
if v.VarType == "string" {
log.Printf("make Add function here %s %s %s\n", pf.Bases.Name, pf.Base.Name, v.VarName)
guiAddStringFunc(newf, pf.Bases.Name, pf.Base.Name, v.VarName)
log.Printf("make Add function here %s %s %s\n", FRUITS, FRUIT, v.VarName)
guiAddStringFunc(newf, FRUITS, FRUIT, v.VarName)
continue
}
if v.VarType == "int64" {
log.Printf("make Add function here %s %s %s\n", pf.Bases.Name, pf.Base.Name, v.VarName)
guiAddIntFunc(newf, pf.Bases.Name, pf.Base.Name, v.VarName)
log.Printf("make Add function here %s %s %s\n", FRUITS, FRUIT, v.VarName)
guiAddIntFunc(newf, FRUITS, FRUIT, v.VarName)
continue
}
/*
@ -63,17 +123,10 @@ func (pb *Files) makeGuiFile(pf *File) error {
log.Printf("Adding %s\n", funcdef)
*/
}
FRUITS := pf.Bases.Name
FRUIT := pf.Base.Name
fRUITS := untitle(pf.Bases.Name)
fRUIT := untitle(pf.Base.Name)
guiUpdate(newf, FRUITS, FRUIT)
guiTableDelete(newf, FRUITS, FRUIT)
guiTableCustom(newf, FRUITS, fRUITS, FRUIT, fRUIT)
fmt.Fprintf(newf, "\n")
fmt.Fprintf(newf, "// END GUI\n")
return nil
}
func headerGui(w io.Writer, pf *File) {

View File

@ -54,6 +54,7 @@ func (pf *File) protoParse() error {
if curmsg == nil {
// log.Info("curmsg == nil", line)
// can't contiue on nil below here
// TODO: look for and format enum structs here
continue
}
// log.Info("curmsg != nil", line)
@ -153,6 +154,7 @@ func parseMsgVar(line string) *MsgVar {
func (pf *File) parseForMessage(line string) *MsgName {
fields := strings.Fields(line)
if len(fields) == 0 || fields[0] != "message" {
// this line doesn't start with message
return nil
}
var msg *MsgName
@ -189,10 +191,28 @@ func (pf *File) parseForMessage(line string) *MsgName {
msg.DoMarshal = true
// log.Info("Added Marshal=true:", msg.Name)
}
if strings.Contains(line, "autogenpb:gui") {
if strings.Contains(line, "`autogenpb:gui") {
log.Info("got autogenpb:gui")
pf.DoGui = true
// os.Exit(-1)
msg.DoGui = true
parts := strings.Split(line, "autogenpb:gu")
if len(parts) != 2 {
log.Info("len(parts) != 2", line)
os.Exit(-1)
}
log.Info("line =", line)
log.Info("end =", parts[1])
end := strings.Split(parts[1], "`")
if end[0] != "i" {
varname := strings.TrimPrefix(end[0], "i:")
msg.GuiVarName = varname
log.Info("varname =", varname)
} else {
if strings.HasSuffix(msgName, "s") {
varname := strings.TrimSuffix(msgName, "s")
msg.GuiVarName = varname
}
}
}
return msg
}