codec: Add Encodable, Decodable interfaces
This commit is contained in:
parent
1f62f6d973
commit
ec965caa27
@ -2,6 +2,14 @@ package codec
|
|||||||
|
|
||||||
import "io"
|
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.
|
// Decoder wraps an [io.Reader] and decodes data from it.
|
||||||
type Decoder struct {
|
type Decoder struct {
|
||||||
io.Reader
|
io.Reader
|
||||||
|
@ -2,6 +2,13 @@ package codec
|
|||||||
|
|
||||||
import "io"
|
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.
|
// Encoder wraps an [io.Writer] and encodes data to it.
|
||||||
type Encoder struct {
|
type Encoder struct {
|
||||||
io.Writer
|
io.Writer
|
||||||
|
Loading…
Reference in New Issue
Block a user