Tizen_4.0 base
[platform/upstream/docker-engine.git] / vendor / github.com / docker / notary / tuf / data / serializer.go
1 package data
2
3 import "github.com/docker/go/canonical/json"
4
5 // Serializer is an interface that can marshal and unmarshal TUF data.  This
6 // is expected to be a canonical JSON marshaller
7 type serializer interface {
8         MarshalCanonical(from interface{}) ([]byte, error)
9         Marshal(from interface{}) ([]byte, error)
10         Unmarshal(from []byte, to interface{}) error
11 }
12
13 // CanonicalJSON marshals to and from canonical JSON
14 type canonicalJSON struct{}
15
16 // MarshalCanonical returns the canonical JSON form of a thing
17 func (c canonicalJSON) MarshalCanonical(from interface{}) ([]byte, error) {
18         return json.MarshalCanonical(from)
19 }
20
21 // Marshal returns the regular non-canonical JSON form of a thing
22 func (c canonicalJSON) Marshal(from interface{}) ([]byte, error) {
23         return json.Marshal(from)
24 }
25
26 // Unmarshal unmarshals some JSON bytes
27 func (c canonicalJSON) Unmarshal(from []byte, to interface{}) error {
28         return json.Unmarshal(from, to)
29 }
30
31 // defaultSerializer is a canonical JSON serializer
32 var defaultSerializer serializer = canonicalJSON{}
33
34 func setDefaultSerializer(s serializer) {
35         defaultSerializer = s
36 }