bad message handling logic. working the issue

This commit is contained in:
Jeff Carr 2025-01-13 03:36:55 -06:00
parent 9cb5064906
commit f74f364187
3 changed files with 45 additions and 14 deletions

View File

@ -39,6 +39,9 @@ func (pb *Files) makeNewSortfile(pf *File) error {
// can't work against slices // can't work against slices
continue continue
} }
if v.VarType != "string" {
continue
}
VARNAME := v.VarName VARNAME := v.VarName
funcdef := newSortType(wSort, PARENT, VARNAME) funcdef := newSortType(wSort, PARENT, VARNAME)
log.Printf("Adding %s\n", funcdef) log.Printf("Adding %s\n", funcdef)
@ -186,6 +189,12 @@ func (pb *Files) makeNewSortfile(pf *File) error {
PARENT := s.MsgName PARENT := s.MsgName
VARNAME := s.VarName VARNAME := s.VarName
if PARENT != VARNAME {
// this does not conform to the autogenpb standard format
continue
}
// special case because of the enforced .proto format // ONLY SUPPORT THIS
msg := pf.findMsg(s.VarType) msg := pf.findMsg(s.VarType)
if msg == nil { if msg == nil {
return fmt.Errorf("failed to find struct %s", s.VarType) return fmt.Errorf("failed to find struct %s", s.VarType)
@ -193,6 +202,9 @@ func (pb *Files) makeNewSortfile(pf *File) error {
// find() // find()
for _, v := range msg.Vars { for _, v := range msg.Vars {
if v.VarType != "string" {
continue
}
if v.IsRepeated { if v.IsRepeated {
continue continue
} }
@ -203,7 +215,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
if PARENT == VARNAME { if PARENT == VARNAME {
// special case because of the enforced .proto format // special case because of the enforced .proto format
FUNCNAME = "FindBy" + v.VarName FUNCNAME = "FindBy" + v.VarName
funcdef := msg.generateFindBy(wSort, FUNCNAME, PARENT, VARNAME, s.VarType, v.VarName) funcdef := msg.generateFindBy(wSort, FUNCNAME, PARENT, s, v)
// func (msg *MsgName) generateFindBy(w io.Writer, FUNCNAME, STRUCT, VARNAME, VARTYPE, COLOR string) string { // func (msg *MsgName) generateFindBy(w io.Writer, FUNCNAME, STRUCT, VARNAME, VARTYPE, COLOR string) string {
log.Printf("Adding %s\n", funcdef) log.Printf("Adding %s\n", funcdef)
} else { } else {
@ -222,6 +234,9 @@ func (pb *Files) makeNewSortfile(pf *File) error {
// delete() functions // delete() functions
for _, v := range msg.Vars { for _, v := range msg.Vars {
if v.VarType != "string" {
continue
}
if v.IsRepeated { if v.IsRepeated {
continue continue
} }
@ -254,6 +269,9 @@ func (pb *Files) makeNewSortfile(pf *File) error {
// AppendBy() functions. todo: fix these so Append() is for simple things and Insert() is for unique keys // AppendBy() functions. todo: fix these so Append() is for simple things and Insert() is for unique keys
var ucount int var ucount int
for _, v := range msg.Vars { for _, v := range msg.Vars {
if v.VarType != "string" {
continue
}
if v.IsRepeated { if v.IsRepeated {
continue continue
} }

View File

@ -7,8 +7,14 @@ import (
// generates Find() and some other stuff // generates Find() and some other stuff
func (msg *MsgName) generateFindBy(w io.Writer, FUNCNAME, STRUCT, VARNAME, VARTYPE, COLOR string) string { func (msg *MsgName) generateFindBy(w io.Writer, FUNCNAME, STRUCT string, sortvals *Sort, childVar *MsgVar) string {
LOCK := msg.getLockname("x") LOCK := msg.getLockname("x")
if childVar.VarType != "string" {
return ""
}
VARNAME := sortvals.VarName
VARTYPE := sortvals.VarType
COLOR := childVar.VarName
funcdef := "func (x *" + STRUCT + ") " + FUNCNAME + "(s string) *" + VARTYPE funcdef := "func (x *" + STRUCT + ") " + FUNCNAME + "(s string) *" + VARTYPE
fmt.Fprintln(w, "// lookup a", STRUCT, "by the ", COLOR) fmt.Fprintln(w, "// lookup a", STRUCT, "by the ", COLOR)

View File

@ -14,6 +14,10 @@ import (
) )
func (msg *MsgName) getLockname(s string) string { func (msg *MsgName) getLockname(s string) string {
if msg.NoMutex {
return "bad"
// return msg.Lockname
}
// leave this function stubbed in for development of autogenpb // leave this function stubbed in for development of autogenpb
// if argv.Mutex { // if argv.Mutex {
// // use the mutex lock from the modified protoc.pb.go file // // use the mutex lock from the modified protoc.pb.go file
@ -120,8 +124,7 @@ func (pf *File) structMatch(line string) bool {
msg = pf.Bases msg = pf.Bases
start = "type " + msg.Name + " struct {" start = "type " + msg.Name + " struct {"
if strings.HasPrefix(line, start) { if strings.HasPrefix(line, start) {
msg.MutexFound = true return msg.setupMutex(pf.Filebase + "Mu")
return true
} }
// ONLY PASS THIS IF YOU DO NOT WANT TO USE MARSHAL() // ONLY PASS THIS IF YOU DO NOT WANT TO USE MARSHAL()
@ -129,22 +132,26 @@ func (pf *File) structMatch(line string) bool {
msg = pf.Base msg = pf.Base
start = "type " + msg.Name + " struct {" start = "type " + msg.Name + " struct {"
if strings.HasPrefix(line, start) { if strings.HasPrefix(line, start) {
msg.MutexFound = true return msg.setupMutex(pf.Filebase + "Mu")
msg.Lockname = "x.Lock"
return true
} }
for _, msg = range pf.MsgNames { for _, msg = range pf.MsgNames {
start = "type " + msg.Name + " struct {" start = "type " + msg.Name + " struct {"
if strings.HasPrefix(line, start) { if strings.HasPrefix(line, start) {
msg.MutexFound = true return msg.setupMutex(pf.Filebase + "Mu")
if msg.NoMutex {
msg.Lockname = pf.Filebase + "Mu" // this should be lowercase. do not export the Mutex
} else {
msg.Lockname = "x.Lock"
}
return true
} }
} }
return false return false
} }
// nameMu should probably be lowercase.
// notsure if it ever makes sense to export a mutex or even if you can
func (msg *MsgName) setupMutex(nameMu string) bool {
msg.MutexFound = true
if msg.NoMutex {
msg.Lockname = nameMu
return false
}
msg.Lockname = "x.Lock"
return true
}