summaryrefslogtreecommitdiff
path: root/package.marshal.go
diff options
context:
space:
mode:
Diffstat (limited to 'package.marshal.go')
-rw-r--r--package.marshal.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/package.marshal.go b/package.marshal.go
new file mode 100644
index 0000000..2c8a4e7
--- /dev/null
+++ b/package.marshal.go
@@ -0,0 +1,42 @@
+package zoopb
+
+// todo: autogen this
+// functions to import and export the protobuf
+
+import (
+ "google.golang.org/protobuf/encoding/protojson"
+ "google.golang.org/protobuf/encoding/prototext"
+ "google.golang.org/protobuf/proto"
+)
+
+// human readable JSON
+func (p *Packages) FormatJSON() string {
+ return protojson.Format(p)
+}
+
+// apparently this isn't supposed to be used?
+// https://protobuf.dev/reference/go/faq/#unstable-text
+// this is a shame because this is much nicer output than JSON Format()
+func (p *Packages) FormatTEXT() string {
+ return prototext.Format(p)
+}
+
+// marshal json
+func (p *Packages) MarshalJSON() ([]byte, error) {
+ return protojson.Marshal(p)
+}
+
+// unmarshal
+func (p *Packages) UnmarshalJSON(data []byte) error {
+ return protojson.Unmarshal(data, p)
+}
+
+// marshal to wire
+func (p *Packages) Marshal() ([]byte, error) {
+ return proto.Marshal(p)
+}
+
+// unmarshal from wire
+func (p *Packages) Unmarshal(data []byte) error {
+ return proto.Unmarshal(data, p)
+}