8 // JSONBuiltin is a Marshaler which marshals/unmarshals into/from JSON
9 // with the standard "encoding/json" package of Golang.
10 // Although it is generally faster for simple proto messages than JSONPb,
11 // it does not support advanced features of protobuf, e.g. map, oneof, ....
13 // The NewEncoder and NewDecoder types return *json.Encoder and
14 // *json.Decoder respectively.
15 type JSONBuiltin struct{}
17 // ContentType always Returns "application/json".
18 func (*JSONBuiltin) ContentType() string {
19 return "application/json"
22 // Marshal marshals "v" into JSON
23 func (j *JSONBuiltin) Marshal(v interface{}) ([]byte, error) {
24 return json.Marshal(v)
27 // Unmarshal unmarshals JSON data into "v".
28 func (j *JSONBuiltin) Unmarshal(data []byte, v interface{}) error {
29 return json.Unmarshal(data, v)
32 // NewDecoder returns a Decoder which reads JSON stream from "r".
33 func (j *JSONBuiltin) NewDecoder(r io.Reader) Decoder {
34 return json.NewDecoder(r)
37 // NewEncoder returns an Encoder which writes JSON stream into "w".
38 func (j *JSONBuiltin) NewEncoder(w io.Writer) Encoder {
39 return json.NewEncoder(w)
42 // Delimiter for newline encoded JSON streams.
43 func (j *JSONBuiltin) Delimiter() []byte {