File: json.go

package info (click to toggle)
singularity-container 4.1.5%2Bds4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 43,876 kB
  • sloc: asm: 14,840; sh: 3,190; ansic: 1,751; awk: 414; makefile: 413; python: 99
file content (62 lines) | stat: -rw-r--r-- 1,502 bytes parent folder | download | duplicates (3)
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
package moby_buildkit_v1_sourcepolicy //nolint:revive

import (
	"github.com/gogo/protobuf/proto"
	"github.com/pkg/errors"
)

// MarshalJSON implements json.Marshaler with custom marshaling for PolicyAction.
// It gives the string form of the enum value.
func (a PolicyAction) MarshalJSON() ([]byte, error) {
	return proto.MarshalJSONEnum(PolicyAction_name, int32(a))
}

func (a *PolicyAction) UnmarshalJSON(data []byte) error {
	val, err := proto.UnmarshalJSONEnum(PolicyAction_value, data, a.String())
	if err != nil {
		return err
	}

	_, ok := PolicyAction_name[val]
	if !ok {
		return errors.Errorf("invalid PolicyAction value: %d", val)
	}
	*a = PolicyAction(val)
	return nil
}

func (a AttrMatch) MarshalJSON() ([]byte, error) {
	return proto.MarshalJSONEnum(AttrMatch_name, int32(a))
}

func (a *AttrMatch) UnmarshalJSON(data []byte) error {
	val, err := proto.UnmarshalJSONEnum(AttrMatch_value, data, a.String())
	if err != nil {
		return err
	}

	_, ok := AttrMatch_name[val]
	if !ok {
		return errors.Errorf("invalid AttrMatch value: %d", val)
	}
	*a = AttrMatch(val)
	return nil
}

func (a MatchType) MarshalJSON() ([]byte, error) {
	return proto.MarshalJSONEnum(MatchType_name, int32(a))
}

func (a *MatchType) UnmarshalJSON(data []byte) error {
	val, err := proto.UnmarshalJSONEnum(MatchType_value, data, a.String())
	if err != nil {
		return err
	}

	_, ok := AttrMatch_name[val]
	if !ok {
		return errors.Errorf("invalid MatchType value: %d", val)
	}
	*a = MatchType(val)
	return nil
}