Updated codec interface and code. Painful stuff
This commit is contained in:
@@ -1,12 +1,47 @@
|
||||
package codec
|
||||
|
||||
// Codec used to encode and decode request/responses
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
Error MessageType = iota
|
||||
Request
|
||||
Response
|
||||
Publication
|
||||
)
|
||||
|
||||
type MessageType int
|
||||
|
||||
// Takes in a connection/buffer and returns a new Codec
|
||||
type NewCodec func(io.ReadWriteCloser) Codec
|
||||
|
||||
// Codec encodes/decodes various types of
|
||||
// messages used within go-micro
|
||||
type Codec interface {
|
||||
// Marshal returns the wire format of v.
|
||||
Marshal(v interface{}) ([]byte, error)
|
||||
// Unmarshal parses the wire format into v.
|
||||
Unmarshal(data []byte, v interface{}) error
|
||||
// String returns the name of the Codec implementation. The returned
|
||||
// string will be used as part of content type in transmission.
|
||||
Encoder
|
||||
Decoder
|
||||
Close() error
|
||||
String() string
|
||||
}
|
||||
|
||||
type Encoder interface {
|
||||
Write(*Message, interface{}) error
|
||||
}
|
||||
|
||||
type Decoder interface {
|
||||
ReadHeader(*Message, MessageType) error
|
||||
ReadBody(interface{}) error
|
||||
}
|
||||
|
||||
// Message represents detailed information about
|
||||
// the communication, likely followed by the body.
|
||||
// In the case of an error, body may be nil.
|
||||
type Message struct {
|
||||
Id uint64
|
||||
Type MessageType
|
||||
Target string
|
||||
Method string
|
||||
Error string
|
||||
Headers map[string]string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user