Debian Codegraph @

api/v1/lib/encoding/json/json.go

raw symbols SCIP
1 package json
2
3 import (
4 "encoding/json"
5
6 "github.com/mesos/mesos-go/api/v1/lib/encoding"
7 "github.com/mesos/mesos-go/api/v1/lib/encoding/framing"
8 )
9
10 // NewEncoder returns a new Encoder of Calls to JSON messages written to
11 // the given io.Writer.
12 func NewEncoder(s encoding.Sink) encoding.Encoder {
13 w := s()
14 return encoding.EncoderFunc(func(m encoding.Marshaler) error {
15 b, err := json.Marshal(m)
16 if err != nil {
17 return err
18 }
19 return w.WriteFrame(b)
20 })
21 }
22
23 // NewDecoder returns a new Decoder of JSON messages read from the given source.
24 func NewDecoder(s encoding.Source) encoding.Decoder {
25 r := s()
26 dec := framing.NewDecoder(r, json.Unmarshal)
27 return encoding.DecoderFunc(func(u encoding.Unmarshaler) error { return dec.Decode(u) })
28 }