diff options
| author | Jeff Carr <[email protected]> | 2024-11-27 13:57:17 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-27 13:57:17 -0600 |
| commit | 2e3e4f98d33d8794a1c8a6aa13e6c9fa92fbcadb (patch) | |
| tree | cd6222e4dc98e9de94981ade9f15f34030cc3d61 /repo.marshal.go | |
| parent | 44caec2e7fc59697ef01835aacf8a03171a42bea (diff) | |
start full refactor to have repo be here
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'repo.marshal.go')
| -rw-r--r-- | repo.marshal.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/repo.marshal.go b/repo.marshal.go new file mode 100644 index 0000000..738ae35 --- /dev/null +++ b/repo.marshal.go @@ -0,0 +1,42 @@ +package gitpb + +// 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 (r *Repo) FormatJSON() string { + return protojson.Format(r) +} + +// 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 (r *Repo) FormatTEXT() string { + return prototext.Format(r) +} + +// marshal json +func (r *Repo) MarshalJSON() ([]byte, error) { + return protojson.Marshal(r) +} + +// unmarshal +func (r *Repo) UnmarshalJSON(data []byte) error { + return protojson.Unmarshal(data, r) +} + +// marshal to wire +func (r *Repo) Marshal() ([]byte, error) { + return proto.Marshal(r) +} + +// unmarshal from wire +func (r *Repo) Unmarshal(data []byte) error { + return proto.Unmarshal(data, r) +} |
