diff options
| author | Jeff Carr <[email protected]> | 2024-11-20 09:31:24 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-20 09:31:24 -0600 |
| commit | 35a2db858f1635f947c2b5f9bbfe9bb64ef7a472 (patch) | |
| tree | 95eb14b030eeb7f5899ce300a3cfc7fed6338651 /helpers.go | |
Day 1v0.0.1
Diffstat (limited to 'helpers.go')
| -rw-r--r-- | helpers.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/helpers.go b/helpers.go new file mode 100644 index 0000000..8ddb213 --- /dev/null +++ b/helpers.go @@ -0,0 +1,55 @@ +package forgepb + +// TODO: autogen this +// functions to import and export the protobuf +// data to and from config files + +import ( + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/encoding/prototext" + "google.golang.org/protobuf/proto" + // "google.golang.org/protobuf/proto" +) + +// human readable JSON +func (p *Repos) 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() +// TODO: fix things so this is the default +func (p *Repos) FormatTEXT() string { + return prototext.Format(p) +} + +// marshal json +func (p *Repos) MarshalJSON() ([]byte, error) { + return protojson.Marshal(p) +} + +// unmarshal +func (p *Repos) UnmarshalJSON(data []byte) error { + return protojson.Unmarshal(data, p) +} + +// marshal to wire +func (m *Repo) Marshal() ([]byte, error) { + return proto.Marshal(m) +} + +// unmarshal from wire +func (m *Repo) Unmarshal(data []byte) error { + return proto.Unmarshal(data, m) +} + +// marshal to wire +func (m *Repos) Marshal() ([]byte, error) { + return proto.Marshal(m) +} + +// unmarshal from wire +func (m *Repos) Unmarshal(data []byte) error { + return proto.Unmarshal(data, m) +} |
