diff options
Diffstat (limited to 'protoParse.go')
| -rw-r--r-- | protoParse.go | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/protoParse.go b/protoParse.go index 8031785..2cefc80 100644 --- a/protoParse.go +++ b/protoParse.go @@ -56,15 +56,15 @@ func (pb *Files) hasPluralMessage(f *File) error { return fmt.Errorf("proto file error %s", f.Filename) } -func (pb *Files) protoParse(f *File) error { +func (pb *Files) protoParse(pf *File) error { // does the file conform to the standard? (also reads in UUID & Version) - if err := pb.hasPluralMessage(f); err != nil { + if err := pb.hasPluralMessage(pf); err != nil { return err } - log.Info(f.Filename, "is valid so far") + log.Info(pf.Filename, "is valid so far") // read in the .proto file - data, err := os.ReadFile(f.Filename) + data, err := os.ReadFile(pf.Filename) if err != nil { return err } @@ -74,7 +74,7 @@ func (pb *Files) protoParse(f *File) error { // parse the proto file for message struct names for _, line := range strings.Split(string(data), "\n") { if strings.HasPrefix(line, "message ") { - curmsg = f.parseForMessage(line) + curmsg = pf.parseForMessage(line) } // this logic isn't right. find end of message with more bravado if strings.HasPrefix(line, "}") { @@ -93,6 +93,10 @@ func (pb *Files) protoParse(f *File) error { // log.Info("Junk in .proto file? line did not contain a message var:", line) continue } + if msgvar.IsRepeated { + log.Info("ADDING ITER MAP", curmsg.Name, msgvar.VarType) + pf.IterMap[curmsg.Name] = msgvar.VarType + } if strings.Contains(line, "autogenpb:sort") { newS := cases.Title(language.English, cases.NoLower).String(parts[1]) @@ -110,9 +114,40 @@ func (pb *Files) protoParse(f *File) error { } curmsg.Vars = append(curmsg.Vars, msgvar) } + pf.makeSortTable() + + // for i, s := range slices.Backward(pf.ToSort) { return nil } +func (pf *File) makeSortTable() { + pf.sortWhat(pf.Bases) + pf.sortWhat(pf.Base) + + // everything else + for _, msg := range pf.MsgNames { + pf.sortWhat(msg) + } +} + +func (pf *File) sortWhat(msg *MsgName) { + for _, v := range msg.Vars { + if !v.IsRepeated { + continue + } + if check := pf.findMsg(v.VarType); check == nil { + // the VarType must be a struct + continue + } + s := new(Sort) + s.MsgName = msg.Name + s.VarType = v.VarType + s.VarName = v.VarName + s.Lockname = msg.Lockname + pf.ToSort = append(pf.ToSort, s) + } +} + func parseMsgVar(line string) *MsgVar { if strings.Contains(line, "//") { parts := strings.Split(line, "//") @@ -169,6 +204,7 @@ func (pf *File) parseForMessage(line string) *MsgName { log.Info("found messge:", msgName) msg.Name = msgName msg.Lockname = pf.Filebase + "Mu" // this should be lowercase. do not export the Mutex + msg.NeedIter = true if strings.Contains(line, "`autogenpb:mutex`") { msg.DoMutex = true |
