From 12fb2c9f0960b121a45e9e0cc580a4bfa38eae89 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 11 Jan 2025 09:49:44 -0600 Subject: [PATCH] hmm. maybe --- generate.go | 44 ++++++++++++++++++++++++++++++++++---------- generateIterator.go | 2 +- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/generate.go b/generate.go index 30e0315..dc07fa8 100644 --- a/generate.go +++ b/generate.go @@ -51,21 +51,45 @@ func (pb *Files) makeNewSortfile(pf *File) error { return nil } -/* -func newGenerate(parent *MsgName, child *MsgName) - var FRUIT string = cases.Title(language.English, cases.NoLower).String(parent.Name) +func (pf *File) newGenerateSort(w io.Writer, parent *MsgName) error { + var FRUIT string = parent.Name var LOCK string = parent.Lockname - var APPLES string = cases.Title(language.English, cases.NoLower).String(pf.Bases.Name) - var APPLE string = cases.Title(language.English, cases.NoLower).String(pf.Base.Name) - var COLORS []string + for _, v := range parent.Vars { - if v.HasUnique { - var COLOR string = cases.Title(language.English, cases.NoLower).String(v.VarName) - COLORS = append(COLORS, COLOR) + if v.IsRepeated { + var APPLES string = v.VarName + var APPLE string = v.VarType + newIter(w, FRUIT, APPLE, APPLES, LOCK) + msg := pf.findMsg(APPLE) + if msg == nil { + return fmt.Errorf("failed to find struct %s", APPLE) + } + for _, v := range msg.Vars { + if v.HasSort { + var COLOR string = v.VarName + newSortBy(w, FRUIT, APPLE, COLOR) + } + + } } } + return nil +} + +func (pf *File) findMsg(s string) *MsgName { + if pf.Bases.Name == s { + return pf.Bases + } + if pf.Base.Name == s { + return pf.Base + } + for _, msg := range pf.MsgNames { + if msg.Name == s { + return msg + } + } + return nil } -*/ func (pf *File) specialBases(wFind io.Writer) { var FRUIT string = cases.Title(language.English, cases.NoLower).String(pf.Bases.Name) diff --git a/generateIterator.go b/generateIterator.go index a291c1e..f54bf60 100644 --- a/generateIterator.go +++ b/generateIterator.go @@ -6,7 +6,7 @@ import ( ) // only make one of these for each message in the protobuf file -func newIter(w io.Writer, FRUIT, APPLE, APPLES, COLOR, LOCK string) { +func newIter(w io.Writer, FRUIT, APPLE, APPLES, LOCK string) { fmt.Fprintln(w, "// DEFINE THE ITERATOR. is unique to the "+APPLE+" protobuf message") fmt.Fprintln(w, "// itializes a new iterator.") fmt.Fprintln(w, "func New"+APPLE+"Iterator(things []*"+APPLE+") *"+APPLE+"Iterator {")