codec: Add Encodable, Decodable interfaces
This commit is contained in:
parent
1f62f6d973
commit
ec965caa27
@ -2,6 +2,14 @@ package codec
|
||||
|
||||
import "io"
|
||||
|
||||
// Decodable is any type that can decode itself from a decoder.
|
||||
type Decodable interface {
|
||||
// Decode reads data from decoder, replacing the data of the object. It
|
||||
// returns the amount of bytes written, and an error if the write
|
||||
// stopped early.
|
||||
Decode(decoder *Decoder) (n int, err error)
|
||||
}
|
||||
|
||||
// Decoder wraps an [io.Reader] and decodes data from it.
|
||||
type Decoder struct {
|
||||
io.Reader
|
||||
|
@ -2,6 +2,13 @@ package codec
|
||||
|
||||
import "io"
|
||||
|
||||
// Encodable is any type that can write itself to an encoder.
|
||||
type Encodable interface {
|
||||
// Encode sends data to encoder. It returns the amount of bytes written,
|
||||
// and an error if the write stopped early.
|
||||
Encode(encoder *Encoder) (n int, err error)
|
||||
}
|
||||
|
||||
// Encoder wraps an [io.Writer] and encodes data to it.
|
||||
type Encoder struct {
|
||||
io.Writer
|
||||
|
Loading…
Reference in New Issue
Block a user