diff options
| author | Jeff Carr <[email protected]> | 2024-11-27 21:05:12 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-27 21:05:12 -0600 |
| commit | 0fc7c2d753bc6cfdc4d64425da1a23c3735b8409 (patch) | |
| tree | a4b7e9f54c46a2c539892cd67cb512171cfd0054 /forgeConfig.marshal.go | |
| parent | 5d031310474e67e211449c434489ec537cabc51f (diff) | |
boo. big mistake on naming protobufs
It's important to really choose good names from the
start. do not think you can rename .proto files later
Good software engineering practices enforced here!
no bullshit. you really want to know what you are planning.
Diffstat (limited to 'forgeConfig.marshal.go')
| -rw-r--r-- | forgeConfig.marshal.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/forgeConfig.marshal.go b/forgeConfig.marshal.go new file mode 100644 index 0000000..63fa744 --- /dev/null +++ b/forgeConfig.marshal.go @@ -0,0 +1,50 @@ +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 *ForgeConfigs) 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 *ForgeConfigs) FormatTEXT() string { + return prototext.Format(p) +} + +// unmarshalTEXT +func (p *ForgeConfigs) UnmarshalTEXT(data []byte) error { + return prototext.Unmarshal(data, p) +} + +// marshal json +func (p *ForgeConfigs) MarshalJSON() ([]byte, error) { + return protojson.Marshal(p) +} + +// unmarshal +func (p *ForgeConfigs) UnmarshalJSON(data []byte) error { + return protojson.Unmarshal(data, p) +} + +// marshal to wire +func (m *ForgeConfigs) Marshal() ([]byte, error) { + return proto.Marshal(m) +} + +// unmarshal from wire +func (m *ForgeConfigs) Unmarshal(data []byte) error { + return proto.Unmarshal(data, m) +} |
