package codec

import (
	"encoding/json"
	"io"
)

type JsonCodec struct{}

func (codec *JsonCodec) EncodeTo(w io.Writer, i interface{}) (err error) {
	return json.NewEncoder(w).Encode(i)
}

func (codec *JsonCodec) DecodeFrom(r io.Reader, i interface{}) (err error) {
	return json.NewDecoder(r).Decode(i)
}

func (codec *JsonCodec) Encode(i interface{}) (b []byte, err error) {
	return json.Marshal(i)
}

func (codec *JsonCodec) Decode(b []byte, i interface{}) (err error) {
	return json.Unmarshal(b, i)
}
