-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct.go
117 lines (98 loc) · 3.13 KB
/
struct.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package structpb
import (
"errors"
"github.com/aperturerobotics/protobuf-go-lite/json"
)
// ErrJSONNotSupported is returned when JSON marshaling or unmarshaling is unsupported
var ErrJSONNotSupported = errors.New("JSON marshal/unmarshal is not supported for Struct")
// MarshalJSON marshals the Struct to JSON.
func (x *Struct) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the Struct from JSON.
func (x *Struct) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// UnmarshalProtoJSON unmarshals a Struct from JSON.
func (x *Struct) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
// The Struct type is not yet supported.
s.SetError(ErrJSONNotSupported)
}
// MarshalProtoJSON marshals a Struct to JSON.
func (x *Struct) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
// The Struct type is not yet supported.
s.SetError(ErrJSONNotSupported)
}
// MarshalJSON marshals the Value to JSON.
func (x *Value) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the Value from JSON.
func (x *Value) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// MarshalProtoJSON marshals a Value to JSON.
func (x *Value) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
// The Value type is not yet supported.
s.SetError(ErrJSONNotSupported)
}
// UnmarshalProtoJSON marshals a Struct to JSON.
func (x *Value) UnmarshalProtoJSON(s *json.UnmarshalState) {
// The Struct type is not yet supported.
s.SetError(ErrJSONNotSupported)
}
// MarshalJSON marshals the ListValue to JSON.
func (x *ListValue) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the ListValue from JSON.
func (x *ListValue) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// MarshalProtoJSON marshals a ListValue to JSON.
func (x *ListValue) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
// The ListValue type is not yet supported.
s.SetError(ErrJSONNotSupported)
}
// UnmarshalProtoJSON marshals a ListValue to JSON.
func (x *ListValue) UnmarshalProtoJSON(s *json.UnmarshalState) {
// The ListValue type is not supported.
s.SetError(ErrJSONNotSupported)
}
// MarshalJSON marshals the NullValue to JSON.
func (x *NullValue) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the NullValue from JSON.
func (x *NullValue) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// MarshalProtoJSON marshals a NullValue to JSON.
func (x *NullValue) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
// The NullValue type is not yet supported.
s.SetError(ErrJSONNotSupported)
}
// UnmarshalProtoJSON marshals a NullValue to JSON.
func (x *NullValue) UnmarshalProtoJSON(s *json.UnmarshalState) {
// The NullValue type is not supported.
s.SetError(ErrJSONNotSupported)
}