-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathcodec.go
More file actions
35 lines (29 loc) · 1.27 KB
/
codec.go
File metadata and controls
35 lines (29 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package network
import (
"io"
"github.com/onflow/flow-go/model/messages"
)
// Codec provides factory functions for encoders and decoders.
type Codec interface {
NewEncoder(w io.Writer) Encoder
NewDecoder(r io.Reader) Decoder
Encode(v interface{}) ([]byte, error)
// Decode decodes a message.
// Expected error returns during normal operations:
// - codec.ErrInvalidEncoding if message encoding is invalid.
// - codec.ErrUnknownMsgCode if message code byte does not match any of the configured message codes.
// - codec.ErrMsgUnmarshal if the codec fails to unmarshal the data to the message type denoted by the message code.
Decode(data []byte) (messages.UntrustedMessage, error)
}
// Encoder encodes the given message into the underlying writer.
type Encoder interface {
Encode(v interface{}) error
}
// Decoder decodes from the underlying reader into the given message.
// Expected error returns during normal operations:
// - codec.ErrInvalidEncoding if message encoding is invalid.
// - codec.ErrUnknownMsgCode if message code byte does not match any of the configured message codes.
// - codec.ErrMsgUnmarshal if the codec fails to unmarshal the data to the message type denoted by the message code.
type Decoder interface {
Decode() (messages.UntrustedMessage, error)
}