tape: Make decoder inherit bufio.Writer

This commit is contained in:
Sasha Koshka 2025-06-28 11:24:32 -04:00
parent e1f58a194a
commit 4930215166

View File

@ -2,6 +2,7 @@ package tape
import "io"
import "math"
import "bufio"
// Decodable is any type that can decode itself from a decoder.
type Decodable interface {
@ -11,9 +12,16 @@ type Decodable interface {
Decode(decoder *Decoder) (n int, err error)
}
// Decoder wraps an [io.Reader] and decodes data from it.
// Decoder decodes data from an [io.Reader].
type Decoder struct {
io.Reader
bufio.Reader
}
// NewDecoder creates a new decoder that reads from reader.
func NewDecoder(reader io.Reader) *Decoder {
decoder := &Decoder { }
decoder.Reader.Reset(reader)
return decoder
}
// ReadFull calls [io.ReadFull] on the reader.
@ -21,12 +29,6 @@ func (this *Decoder) ReadFull(buffer []byte) (n int, err error) {
return io.ReadFull(this, buffer)
}
// ReadByte decodes a single byte from the input reader.
func (this *Decoder) ReadByte() (value byte, n int, err error) {
uncasted, n, err := this.ReadUint8()
return byte(uncasted), n, err
}
// ReadInt8 decodes an 8-bit signed integer from the input reader.
func (this *Decoder) ReadInt8() (value int8, n int, err error) {
uncasted, n, err := this.ReadUint8()