{"modulePath":"github.com/printfcoder/go-micro","version":"v0.23.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package codec\n\nPackage codec is an interface for encoding messages\n\n## Types\n\n```go\ntype Codec interface {\n\tReader\n\tWriter\n\tClose() error\n\tString() string\n}\n```\nCodec encodes/decodes various types of messages used within go-micro. ReadHeader and ReadBody are called in pairs to read requests/responses from the connection. Close is called when finished with the connection. ReadBody may be called with a nil argument to force the body to be read and discarded.\n\n```go\ntype Marshaler interface {\n\tMarshal(interface{}) ([]byte, error)\n\tUnmarshal([]byte, interface{}) error\n\tString() string\n}\n```\nMarshaler is a simple encoding interface used for the broker/transport where headers are not supported by the underlying implementation.\n\n```go\ntype Message struct {\n\tId       string\n\tType     MessageType\n\tTarget   string\n\tMethod   string\n\tEndpoint string\n\tError    string\n\n\t// The values read from the socket\n\tHeader map[string]string\n\tBody   []byte\n}\n```\nMessage represents detailed information about the communication, likely followed by the body. In the case of an error, body may be nil.\n\n```go\ntype MessageType int\n```\n\n```go\nconst (\n\tError MessageType = iota\n\tRequest\n\tResponse\n\tPublication\n)\n```\n\n```go\ntype NewCodec func(io.ReadWriteCloser) Codec\n```\nTakes in a connection/buffer and returns a new Codec\n\n```go\ntype Reader interface {\n\tReadHeader(*Message, MessageType) error\n\tReadBody(interface{}) error\n}\n```\n\n```go\ntype Writer interface {\n\tWrite(*Message, interface{}) error\n}\n```\n\n","path":"github.com/printfcoder/go-micro/codec","name":"codec","synopsis":"Package codec is an interface for encoding messages","isRedistributable":true}
