tape: Encoder inherits bufio.Writer, need to do same for decoder

This commit is contained in:
Sasha Koshka 2025-06-28 06:23:18 -04:00
parent 3eb826735b
commit 08fe3d45dd

View File

@ -2,6 +2,7 @@ package tape
import "io" import "io"
import "math" import "math"
import "bufio"
// Encodable is any type that can write itself to an encoder. // Encodable is any type that can write itself to an encoder.
type Encodable interface { type Encodable interface {
@ -10,14 +11,16 @@ type Encodable interface {
Encode(encoder *Encoder) (n int, err error) Encode(encoder *Encoder) (n int, err error)
} }
// Encoder wraps an [io.Writer] and encodes data to it. // Encoder encodes data to an io.Writer.
type Encoder struct { type Encoder struct {
io.Writer bufio.Writer
} }
// WriteByte encodes a single byte to the output writer. // NewEncoder creates a new encoder that writes to writer.
func (this *Encoder) WriteByte(value byte) (n int, err error) { func NewEncoder(writer io.Writer) *Encoder {
return this.WriteByte(uint8(value)) encoder := &Encoder { }
encoder.Reset(writer)
return encoder
} }
// WriteInt8 encodes an 8-bit signed integer to the output writer. // WriteInt8 encodes an 8-bit signed integer to the output writer.