mirror of
https://github.com/geektutu/7days-golang.git
synced 2024-04-21 12:32:11 +00:00
35 lines
629 B
Go
35 lines
629 B
Go
package codec
|
|
|
|
import (
|
|
"io"
|
|
)
|
|
|
|
type Header struct {
|
|
ServiceMethod string // format "Service.Method"
|
|
Seq uint64 // sequence number chosen by client
|
|
Error string
|
|
}
|
|
|
|
type Codec interface {
|
|
io.Closer
|
|
ReadHeader(*Header) error
|
|
ReadBody(interface{}) error
|
|
Write(*Header, interface{}) error
|
|
}
|
|
|
|
type NewCodecFunc func(io.ReadWriteCloser) Codec
|
|
|
|
type Type string
|
|
|
|
const (
|
|
GobType Type = "application/gob"
|
|
JsonType Type = "application/json" // not implemented
|
|
)
|
|
|
|
var NewCodecFuncMap map[Type]NewCodecFunc
|
|
|
|
func init() {
|
|
NewCodecFuncMap = make(map[Type]NewCodecFunc)
|
|
NewCodecFuncMap[GobType] = NewGobCodec
|
|
}
|