summaryrefslogtreecommitdiff
path: root/marshal.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-29 12:35:12 -0600
committerJeff Carr <[email protected]>2024-11-29 12:35:12 -0600
commit7a1b9608581ad4f2169198be1cbd30093beaa5b3 (patch)
tree93d0c718c8f62ab13658bfd399e8876c63d6bc1e /marshal.go
parent45b343bee8b1b38ad89899f31624613925bb408e (diff)
marshal argv options
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'marshal.go')
-rw-r--r--marshal.go30
1 files changed, 18 insertions, 12 deletions
diff --git a/marshal.go b/marshal.go
index 07042f0..3ed41ff 100644
--- a/marshal.go
+++ b/marshal.go
@@ -28,8 +28,14 @@ func marshal(names map[string]string) {
fmt.Fprintln(w, ")")
fmt.Fprintln(w, "")
- marshalThing(w, names["Base"])
- marshalThing(w, names["Bases"])
+ if len(argv.Marshal) == 0 {
+ marshalThing(w, names["Base"])
+ marshalThing(w, names["Bases"])
+ } else {
+ for _, v := range argv.Marshal {
+ marshalThing(w, v)
+ }
+ }
}
func marshalThing(w io.Writer, thing string) {
@@ -38,29 +44,29 @@ func marshalThing(w io.Writer, thing string) {
fmt.Fprintln(w, " return protojson.Format(r)")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
- fmt.Fprintln(w, "// apparently this isn't stable")
- fmt.Fprintln(w, "// https://protobuf.dev/reference/go/faq/#unstable-text")
- fmt.Fprintln(w, "// but it's so awesome I'm using it by default to try to fix the problems with it")
- fmt.Fprintln(w, "func (r *"+thing+") FormatTEXT() string {")
- fmt.Fprintln(w, " return prototext.Format(r)")
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w, "")
fmt.Fprintln(w, "// marshal json")
fmt.Fprintln(w, "func (r *"+thing+") MarshalJSON() ([]byte, error) {")
fmt.Fprintln(w, " return protojson.Marshal(r)")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
- fmt.Fprintln(w, "// unmarshal")
+ fmt.Fprintln(w, "// unmarshal json")
fmt.Fprintln(w, "func (r *"+thing+") UnmarshalJSON(data []byte) error {")
fmt.Fprintln(w, " return protojson.Unmarshal(data, r)")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
- fmt.Fprintln(w, "// marshal to wire")
+ fmt.Fprintln(w, "// apparently this isn't stable, but it's awesomely better")
+ fmt.Fprintln(w, "// https://protobuf.dev/reference/go/faq/#unstable-text")
+ fmt.Fprintln(w, "// it's so great for config files, I'm using it by default to try to fix the problems with it")
+ fmt.Fprintln(w, "func (r *"+thing+") FormatTEXT() string {")
+ fmt.Fprintln(w, " return prototext.Format(r)")
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, "// marshal to wire. This is called winning.")
fmt.Fprintln(w, "func (r *"+thing+") Marshal() ([]byte, error) {")
fmt.Fprintln(w, " return proto.Marshal(r)")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
- fmt.Fprintln(w, "// unmarshal from wire")
+ fmt.Fprintln(w, "// unmarshal from wire. You have won.")
fmt.Fprintln(w, "func (r *"+thing+") Unmarshal(data []byte) error {")
fmt.Fprintln(w, " return proto.Unmarshal(data, r)")
fmt.Fprintln(w, "}")