| 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 |
|
| 11 |
|
| 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 |
|
| 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 |
} |