From 0aa3457e7df607bf8e9e46184cffec7292e100d4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 9 Jan 2025 05:00:29 -0600 Subject: [PATCH] marshal is converted to using the protobuf --- main.go | 21 ++++----------------- marshal.go | 28 +++++++++++----------------- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/main.go b/main.go index 7903111..8e8aa09 100644 --- a/main.go +++ b/main.go @@ -159,27 +159,14 @@ func main() { pb.addMutex(f) // if foo.pb.go still doesn't exist, protoc failed - // exit here - if !shell.Exists(sortmap["protoc"]) { - log.Info("protoc build error.", sortmap["protoc"], "failed to be created with protoc and proto-gen-go") + if !shell.Exists(pbfile) { + log.Info("protoc build error.", pbfile) badExit(errors.New("failed to be created with protoc and proto-gen-go")) } - if argv.NoSort { - // log.Info("not making sort.pb.go file (--no-sort == true)") - } else { - if len(uniqueKeys) != 0 { - } - makeSortfile() - } - - if argv.NoMarshal { - // log.Info("not making marshal.pb.go file (--no-marshal == true)") - } else { - // make the foo.marshal.pb.go file - marshal(sortmap) - } + pb.marshal(f) + // pb.makeSortfile(f) } func okExit(s string) { diff --git a/marshal.go b/marshal.go index 7585a6d..43d8c14 100644 --- a/marshal.go +++ b/marshal.go @@ -8,19 +8,16 @@ import ( "go.wit.com/log" ) -func marshal(names map[string]string) { - +// makes Marshal and Unmarshal functions for protoWIRE protoTEXT and protoJSON +func (pb *Files) marshal(f *File) { if argv.DryRun { - for k, v := range names { - log.Info(k, "=", v) - } - os.Exit(0) + return } - w, _ := os.OpenFile(names["protobase"]+".marshal.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + w, _ := os.OpenFile(f.Filebase+".marshal.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) - fmt.Fprintln(w, "package "+names["package"]) headerComment(w) + fmt.Fprintf(w, "package %s\n", f.Package) fmt.Fprintln(w, "import (") fmt.Fprintln(w, " \"google.golang.org/protobuf/encoding/protojson\"") fmt.Fprintln(w, " \"google.golang.org/protobuf/encoding/prototext\"") @@ -28,15 +25,12 @@ func marshal(names map[string]string) { fmt.Fprintln(w, ")") fmt.Fprintln(w, "") - for _, v := range marshalKeys { - // log.Info("found marshal key in .proto", v) - marshalThing(w, v) - } - - // marshalThing(w, names["Base"]) - // marshalThing(w, names["Bases"]) - for _, v := range argv.Marshal { - marshalThing(w, v) + for _, msg := range f.MsgNames { + if msg.DoMarshal { + marshalThing(w, msg.Name) + } else { + log.Info("Skipping. DoMarshal = false for", msg.Name) + } } }