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 (96 lines) | stat: -rw-r--r-- 2,013 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
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
package pb

import "encoding/json"

func (m *Op) UnmarshalJSON(data []byte) error {
	var v struct {
		Inputs []*Input `json:"inputs,omitempty"`
		Op     struct {
			*Op_Exec
			*Op_Source
			*Op_File
			*Op_Build
			*Op_Merge
			*Op_Diff
		}
		Platform    *Platform          `json:"platform,omitempty"`
		Constraints *WorkerConstraints `json:"constraints,omitempty"`
	}

	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}

	m.Inputs = v.Inputs
	switch {
	case v.Op.Op_Exec != nil:
		m.Op = v.Op.Op_Exec
	case v.Op.Op_Source != nil:
		m.Op = v.Op.Op_Source
	case v.Op.Op_File != nil:
		m.Op = v.Op.Op_File
	case v.Op.Op_Build != nil:
		m.Op = v.Op.Op_Build
	case v.Op.Op_Merge != nil:
		m.Op = v.Op.Op_Merge
	case v.Op.Op_Diff != nil:
		m.Op = v.Op.Op_Diff
	}
	m.Platform = v.Platform
	m.Constraints = v.Constraints
	return nil
}

func (m *FileAction) UnmarshalJSON(data []byte) error {
	var v struct {
		Input          InputIndex  `json:"input"`
		SecondaryInput InputIndex  `json:"secondaryInput"`
		Output         OutputIndex `json:"output"`
		Action         struct {
			*FileAction_Copy
			*FileAction_Mkfile
			*FileAction_Mkdir
			*FileAction_Rm
		}
	}

	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}

	m.Input = v.Input
	m.SecondaryInput = v.SecondaryInput
	m.Output = v.Output
	switch {
	case v.Action.FileAction_Copy != nil:
		m.Action = v.Action.FileAction_Copy
	case v.Action.FileAction_Mkfile != nil:
		m.Action = v.Action.FileAction_Mkfile
	case v.Action.FileAction_Mkdir != nil:
		m.Action = v.Action.FileAction_Mkdir
	case v.Action.FileAction_Rm != nil:
		m.Action = v.Action.FileAction_Rm
	}
	return nil
}

func (m *UserOpt) UnmarshalJSON(data []byte) error {
	var v struct {
		User struct {
			*UserOpt_ByName
			*UserOpt_ByID
		}
	}

	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}

	switch {
	case v.User.UserOpt_ByName != nil:
		m.User = v.User.UserOpt_ByName
	case v.User.UserOpt_ByID != nil:
		m.User = v.User.UserOpt_ByID
	}
	return nil
}