summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-06 23:29:42 -0500
committerJeff Carr <[email protected]>2025-10-06 23:29:42 -0500
commitd8ce54edfbc84d6880f06373b226976a1e702090 (patch)
tree78ef3ed626bba75b6655e32aa8aa050d422d80d5
parent1cc17983d5867a5254845bed559f8f460d360928 (diff)
autogenerated pb.Load() and pb.Save() very nice
-rw-r--r--example/fruit.proto1
-rw-r--r--file.proto1
-rw-r--r--generateHeader.go3
-rw-r--r--protoParse.go5
4 files changed, 10 insertions, 0 deletions
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<string, string> 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