summaryrefslogtreecommitdiff
path: root/generateMarshal.go
diff options
context:
space:
mode:
Diffstat (limited to 'generateMarshal.go')
-rw-r--r--generateMarshal.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/generateMarshal.go b/generateMarshal.go
index 18758bb..8474efe 100644
--- a/generateMarshal.go
+++ b/generateMarshal.go
@@ -24,23 +24,28 @@ func (pb *Files) marshal(f *File) {
fmt.Fprintln(w, "")
if f.Bases.DoMarshal {
- marshalThing(w, f.Bases.Name)
+ if f.Uuid == "" {
+ marshalThing(w, f.Bases.Name, false)
+ } else {
+ // if the Uuid is set, run fixUuid() in Marshal()
+ marshalThing(w, f.Bases.Name, true)
+ }
}
if f.Base.DoMarshal {
- marshalThing(w, f.Base.Name)
+ marshalThing(w, f.Base.Name, false)
}
for _, msg := range f.MsgNames {
if msg.DoMarshal {
- marshalThing(w, msg.Name)
+ marshalThing(w, msg.Name, false)
} else {
// log.Info("Skipping. DoMarshal = false for", msg.Name)
}
}
}
-func marshalThing(w io.Writer, thing string) {
+func marshalThing(w io.Writer, thing string, fix bool) {
fmt.Fprintln(w, "// human readable JSON")
fmt.Fprintln(w, "func (v *"+thing+") FormatJSON() string {")
fmt.Fprintln(w, " return protojson.Format(v)")
@@ -60,6 +65,9 @@ func marshalThing(w io.Writer, thing string) {
fmt.Fprintln(w, "// https://protobuf.dev/reference/go/faq/#unstable-text")
fmt.Fprintln(w, "// it's brilliant for config files!")
fmt.Fprintln(w, "func (v *"+thing+") FormatTEXT() string {")
+ if fix {
+ fmt.Fprintln(w, " v.fixUuid()")
+ }
fmt.Fprintln(w, " return prototext.Format(v)")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
@@ -70,6 +78,9 @@ func marshalThing(w io.Writer, thing string) {
fmt.Fprintln(w, "")
fmt.Fprintln(w, "// marshal to wire. This is called winning.")
fmt.Fprintln(w, "func (v *"+thing+") Marshal() ([]byte, error) {")
+ if fix {
+ fmt.Fprintln(w, " v.fixUuid()")
+ }
fmt.Fprintln(w, " return proto.Marshal(v)")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")