summaryrefslogtreecommitdiff
path: root/helpers.go
blob: 93d0a73925b9e88d38296364dc06d8792140f355 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package zoopb

// 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"
)

// 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)
}

// marshal
func (p *Packages) MarshalJSON() ([]byte, error) {
	return protojson.Marshal(p)
}

// unmarshal
func (p *Packages) UnmarshalJSON(data []byte) error {
	return protojson.Unmarshal(data, p)
}