-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
57 lines (44 loc) · 1.43 KB
/
util.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
package main
import "encoding/json"
// Hacky function to Marshal a MatchDetail into a MarshaledMatchDetail.
// Marshals all the fields that aren't basic types like strings and integers.
func (v *MatchDetail) Marshal() (*MarshaledMatchDetail, error) {
var buf []byte
var err error
e := MarshaledMatchDetail{(*v).BaseMatchDetail, nil, nil, nil, nil}
if buf, err = json.Marshal(v.ParticipantIdentities); err != nil {
return nil, err
}
e.ParticipantIdentities = buf
if buf, err = json.Marshal(v.Participants); err != nil {
return nil, err
}
e.Participants = buf
if buf, err = json.Marshal(v.Teams); err != nil {
return nil, err
}
e.Teams = buf
if buf, err = json.Marshal(v.Timeline); err != nil {
return nil, err
}
e.Timeline = buf
return &e, nil
}
// Hacky function to Unmarshal a MarshaledMatchDetail into a MatchDetail.
// Unmarshals all the fields that aren't basic types like strings and integers.
func (v *MarshaledMatchDetail) Unmarshal() (*MatchDetail, error) {
e := MatchDetail{(*v).BaseMatchDetail, nil, nil, nil, Timeline{}}
if err := json.Unmarshal(v.ParticipantIdentities, &e.ParticipantIdentities); err != nil {
return nil, err
}
if err := json.Unmarshal(v.Participants, &e.Participants); err != nil {
return nil, err
}
if err := json.Unmarshal(v.Teams, &e.Teams); err != nil {
return nil, err
}
if err := json.Unmarshal(v.Timeline, &e.Timeline); err != nil {
return nil, err
}
return &e, nil
}