remove codecs

This commit is contained in:
Asim Aslam
2019-01-10 09:42:02 +00:00
parent 6e0e4a684c
commit c086c33bb3
13 changed files with 93 additions and 148 deletions

View File

@@ -1,10 +0,0 @@
package codec
// Codec is used for encoding where the transport doesn't natively support
// headers in the message type. In this case the entire message is
// encoded as the payload
type Codec interface {
Marshal(interface{}) ([]byte, error)
Unmarshal([]byte, interface{}) error
String() string
}

View File

@@ -1,25 +0,0 @@
package json
import (
"encoding/json"
"github.com/micro/go-micro/transport/codec"
)
type jsonCodec struct{}
func (j jsonCodec) Marshal(v interface{}) ([]byte, error) {
return json.Marshal(v)
}
func (j jsonCodec) Unmarshal(d []byte, v interface{}) error {
return json.Unmarshal(d, v)
}
func (j jsonCodec) String() string {
return "json"
}
func NewCodec() codec.Codec {
return jsonCodec{}
}

View File

@@ -1,35 +0,0 @@
package noop
import (
"errors"
"github.com/micro/go-micro/transport"
"github.com/micro/go-micro/transport/codec"
)
type noopCodec struct{}
func (n noopCodec) Marshal(v interface{}) ([]byte, error) {
msg, ok := v.(*transport.Message)
if !ok {
return nil, errors.New("invalid message")
}
return msg.Body, nil
}
func (n noopCodec) Unmarshal(d []byte, v interface{}) error {
msg, ok := v.(*transport.Message)
if !ok {
return errors.New("invalid message")
}
msg.Body = d
return nil
}
func (n noopCodec) String() string {
return "noop"
}
func NewCodec() codec.Codec {
return noopCodec{}
}

View File

@@ -5,12 +5,12 @@ import (
"crypto/tls"
"time"
"github.com/micro/go-micro/transport/codec"
"github.com/micro/go-micro/codec"
)
type Options struct {
Addrs []string
Codec codec.Codec
Codec codec.Marshaler
Secure bool
TLSConfig *tls.Config
// Timeout sets the timeout for Send/Recv
@@ -50,7 +50,7 @@ func Addrs(addrs ...string) Option {
// Codec sets the codec used for encoding where the transport
// does not support message headers
func Codec(c codec.Codec) Option {
func Codec(c codec.Marshaler) Option {
return func(o *Options) {
o.Codec = c
}