-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathunmarshalHelpers.go
61 lines (53 loc) · 1.5 KB
/
unmarshalHelpers.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
package refmt
import (
"io"
"github.com/polydawn/refmt/cbor"
"github.com/polydawn/refmt/json"
"github.com/polydawn/refmt/obj/atlas"
)
type DecodeOptions interface {
IsDecodeOptions() // marker method.
}
func Unmarshal(opts DecodeOptions, data []byte, v interface{}) error {
switch o2 := opts.(type) {
case json.DecodeOptions:
return json.Unmarshal(data, v)
case cbor.DecodeOptions:
return cbor.Unmarshal(o2, data, v)
default:
panic("incorrect usage: unknown DecodeOptions type")
}
}
func UnmarshalAtlased(opts DecodeOptions, data []byte, v interface{}, atl atlas.Atlas) error {
switch o2 := opts.(type) {
case json.DecodeOptions:
return json.UnmarshalAtlased(data, v, atl)
case cbor.DecodeOptions:
return cbor.UnmarshalAtlased(o2, data, v, atl)
default:
panic("incorrect usage: unknown DecodeOptions type")
}
}
type Unmarshaller interface {
Unmarshal(v interface{}) error
}
func NewUnmarshaller(opts DecodeOptions, r io.Reader) Unmarshaller {
switch o2 := opts.(type) {
case json.DecodeOptions:
return json.NewUnmarshaller(r)
case cbor.DecodeOptions:
return cbor.NewUnmarshaller(o2, r)
default:
panic("incorrect usage: unknown DecodeOptions type")
}
}
func NewUnmarshallerAtlased(opts DecodeOptions, r io.Reader, atl atlas.Atlas) Unmarshaller {
switch o2 := opts.(type) {
case json.DecodeOptions:
return json.NewUnmarshallerAtlased(r, atl)
case cbor.DecodeOptions:
return cbor.NewUnmarshallerAtlased(o2, r, atl)
default:
panic("incorrect usage: unknown DecodeOptions type")
}
}