zoopb/package.marshal.go

43 lines
980 B
Go
Raw Permalink Normal View History

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"
2024-11-15 19:53:06 -06:00
"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)
}
2024-11-15 19:53:06 -06:00
// 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)
}
2024-11-15 19:53:06 -06:00
// 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)
}