From d8ce54edfbc84d6880f06373b226976a1e702090 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 6 Oct 2025 23:29:42 -0500 Subject: autogenerated pb.Load() and pb.Save() very nice --- example/fruit.proto | 1 + file.proto | 1 + generateHeader.go | 3 +++ protoParse.go | 5 +++++ 4 files changed, 10 insertions(+) diff --git a/example/fruit.proto b/example/fruit.proto index f7b8f7d..2f2c908 100644 --- a/example/fruit.proto +++ b/example/fruit.proto @@ -74,4 +74,5 @@ message Fruits { // `autogenpb:marshal` ` repeated Fruit Fruits = 3; // THIS MUST BE "Fruit" and then "Fruit" + "s" int64 cost = 4; // you can add additional things here but the three lines above must conform to the standard above map junk = 5; + string filename = 6; // `autogenpb:sort` -- this enables autogenerated pb.Load() and pb.Save() } diff --git a/file.proto b/file.proto index 070da89..c5abf35 100644 --- a/file.proto +++ b/file.proto @@ -105,6 +105,7 @@ message File { // `autogenpb:var:w io.Wri string goPath = 13; // the version to use in a func NewMsgName() bool doGui = 14; // if a gui.pb.go file should be created bool doHTTP = 15; // http.pb.go + bool doSave = 16; // generate autosave functions (in marshal.go ?) } // I know, I know, the whole point of using protobuf // is so you don't need a uuid or versions because it's diff --git a/generateHeader.go b/generateHeader.go index 4f2b4b6..60d08e7 100644 --- a/generateHeader.go +++ b/generateHeader.go @@ -77,6 +77,9 @@ func (pf *File) addNewFunc(w io.Writer) { fmt.Fprintln(w, " x := new("+STRUCT+")") fmt.Fprintln(w, " x.Uuid = \""+UUID+"\"") fmt.Fprintln(w, " x.Version = \""+VERSION+" "+pf.GoPath+"\"") + if pf.DoSave { + fmt.Fprintln(w, " // x.Filename = \""+VERSION+" "+pf.GoPath+"\"") + } fmt.Fprintln(w, " return x") fmt.Fprintln(w, "}") } diff --git a/protoParse.go b/protoParse.go index 33951d2..c8ac75c 100644 --- a/protoParse.go +++ b/protoParse.go @@ -204,6 +204,11 @@ func (pf *File) parseForMessage(line string) *MsgName { msg.DoHTTP = true msg.DoMarshal = true // http requires Marshal } + + if strings.Contains(line, "`autogenpb:autosave") { + pf.DoSave = true + } + if strings.Contains(line, "`autogenpb:gui") { log.Info("got autogenpb:gui") pf.DoGui = true -- cgit v1.2.3