Codec

Example:broadcast

Currently rpcx supports four type of codec:

  1. // SerializeType defines serialization type of payload.
  2. type SerializeType byte
  3. const (
  4. // SerializeNone uses raw []byte and don't serialize/deserialize
  5. SerializeNone SerializeType = iota
  6. // JSON for payload.
  7. JSON
  8. // ProtoBuffer for payload.
  9. ProtoBuffer
  10. // MsgPack for payload
  11. MsgPack
  12. )

Service use the same codec with clients. Clients set SerializeType in options. The default option use msgpack.

  1. var DefaultOption = Option{
  2. Retries: 3,
  3. RPCPath: share.DefaultRPCPath,
  4. ConnectTimeout: 10 * time.Second,
  5. Breaker: CircuitBreaker,
  6. SerializeType: protocol.MsgPack,
  7. CompressType: protocol.None,
  8. }

The option is set when create XClient:

  1. func NewXClient(servicePath string, failMode FailMode, selectMode SelectMode, discovery ServiceDiscovery, option Option)

SerializeNone

No codec for data and use raw slice of bytes.

Clients and serices can encode/decode payload by their customized codec, for example, Avro.

JSON

JSON is a general data format and can be used by many programming language.

But its performance is not better than protobuf and messagepack.

Protobuf

Protobuf is a performant codec by Google and it is used in grpc and many projects.

MsgPack

messagepack is another performant codec and it is cross-platform too.

By smallnest updated 2018-03-27 11:12:10

原文:

http://doc.rpcx.site/part3/codec.html