forked from drand/drand
/
json_marshaller.go
41 lines (32 loc) 路 1000 Bytes
/
json_marshaller.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
package net
import (
"io"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/nikkolasg/hexjson"
)
// HexJSON transforms json into hex string instead of b64
type HexJSON struct{}
// ContentType always Returns "application/json".
func (*HexJSON) ContentType() string {
return "application/json"
}
// Marshal marshals "v" into JSON
func (j *HexJSON) Marshal(v interface{}) ([]byte, error) {
return json.Marshal(v)
}
// Unmarshal unmarshals JSON data into "v".
func (j *HexJSON) Unmarshal(data []byte, v interface{}) error {
return json.Unmarshal(data, v)
}
// NewDecoder returns a Decoder which reads JSON stream from "r".
func (j *HexJSON) NewDecoder(r io.Reader) runtime.Decoder {
return json.NewDecoder(r)
}
// NewEncoder returns an Encoder which writes JSON stream into "w".
func (j *HexJSON) NewEncoder(w io.Writer) runtime.Encoder {
return json.NewEncoder(w)
}
// Delimiter for newline encoded JSON streams.
func (j *HexJSON) Delimiter() []byte {
return []byte("\n")
}