rpc-go/codec/codec.go
2018-08-22 18:04:25 +09:00

45 lines
991 B
Go

package codec
import (
css "git.loafle.net/overflow/server-go/socket"
)
type Codec interface {
Encode(message []byte) ([]byte, error)
Decode(message []byte) ([]byte, error)
}
type codec struct {
}
func (_ *codec) Encode(message []byte) ([]byte, error) {
return message, nil
}
func (_ *codec) Decode(message []byte) ([]byte, error) {
return message, nil
}
var DefaultCodec = &codec{}
type CodecSelector interface {
Encode(message []byte) (messageType int, encMessage []byte, err error)
Decode(messageType int, message []byte) (decMessage []byte, err error)
}
type codecSelector struct {
}
func (_ *codecSelector) Encode(message []byte) (messageType int, encMessage []byte, err error) {
messageType = css.TextMessage
encMessage, err = DefaultCodec.Encode(message)
return
}
func (_ *codecSelector) Decode(messageType int, message []byte) (decMessage []byte, err error) {
decMessage, err = DefaultCodec.Decode(message)
return
}
var DefaultCodecSelector = &codecSelector{}