might be pretty good stuff
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
69093ef5de
commit
45b343bee8
42
blah_marshal
42
blah_marshal
|
@ -1,42 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
|
@ -38,9 +38,9 @@ func marshalThing(w io.Writer, thing string) {
|
||||||
fmt.Fprintln(w, " return protojson.Format(r)")
|
fmt.Fprintln(w, " return protojson.Format(r)")
|
||||||
fmt.Fprintln(w, "}")
|
fmt.Fprintln(w, "}")
|
||||||
fmt.Fprintln(w, "")
|
fmt.Fprintln(w, "")
|
||||||
fmt.Fprintln(w, "// apparently this isn't supposed to be used?")
|
fmt.Fprintln(w, "// apparently this isn't stable")
|
||||||
fmt.Fprintln(w, "// https://protobuf.dev/reference/go/faq/#unstable-text")
|
fmt.Fprintln(w, "// https://protobuf.dev/reference/go/faq/#unstable-text")
|
||||||
fmt.Fprintln(w, "// this is a shame because this is much nicer output than JSON Format()")
|
fmt.Fprintln(w, "// but it's so awesome I'm using it by default to try to fix the problems with it")
|
||||||
fmt.Fprintln(w, "func (r *"+thing+") FormatTEXT() string {")
|
fmt.Fprintln(w, "func (r *"+thing+") FormatTEXT() string {")
|
||||||
fmt.Fprintln(w, " return prototext.Format(r)")
|
fmt.Fprintln(w, " return prototext.Format(r)")
|
||||||
fmt.Fprintln(w, "}")
|
fmt.Fprintln(w, "}")
|
||||||
|
|
Loading…
Reference in New Issue