Debian Codegraph @

buildkit/sourcepolicy/pb/json.go

raw symbols SCIP
1 package moby_buildkit_v1_sourcepolicy //nolint:revive,staticcheck
2
3 import (
4 "github.com/moby/buildkit/util/gogo/proto"
5 "github.com/pkg/errors"
6 )
7
8 // MarshalJSON implements json.Marshaler with custom marshaling for PolicyAction.
9 // It gives the string form of the enum value.
10 func (a PolicyAction) MarshalJSON() ([]byte, error) {
11 return proto.MarshalJSONEnum(PolicyAction_name, int32(a))
12 }
13
14 func (a *PolicyAction) UnmarshalJSON(data []byte) error {
15 val, err := proto.UnmarshalJSONEnum(PolicyAction_value, data, a.String())
16 if err != nil {
17 return err
18 }
19
20 _, ok := PolicyAction_name[val]
21 if !ok {
22 return errors.Errorf("invalid PolicyAction value: %d", val)
23 }
24 *a = PolicyAction(val)
25 return nil
26 }
27
28 func (a AttrMatch) MarshalJSON() ([]byte, error) {
29 return proto.MarshalJSONEnum(AttrMatch_name, int32(a))
30 }
31
32 func (a *AttrMatch) UnmarshalJSON(data []byte) error {
33 val, err := proto.UnmarshalJSONEnum(AttrMatch_value, data, a.String())
34 if err != nil {
35 return err
36 }
37
38 _, ok := AttrMatch_name[val]
39 if !ok {
40 return errors.Errorf("invalid AttrMatch value: %d", val)
41 }
42 *a = AttrMatch(val)
43 return nil
44 }
45
46 func (a MatchType) MarshalJSON() ([]byte, error) {
47 return proto.MarshalJSONEnum(MatchType_name, int32(a))
48 }
49
50 func (a *MatchType) UnmarshalJSON(data []byte) error {
51 val, err := proto.UnmarshalJSONEnum(MatchType_value, data, a.String())
52 if err != nil {
53 return err
54 }
55
56 _, ok := AttrMatch_name[val]
57 if !ok {
58 return errors.Errorf("invalid MatchType value: %d", val)
59 }
60 *a = MatchType(val)
61 return nil
62 }