summaryrefslogtreecommitdiff
path: root/forgeConfig.marshal.go
blob: 63fa744ec6d886de381ad293be6d439f10eb5a7b (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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)
}