From 08fe3d45ddd856ab9a2646b23bbdce8d5be660ed Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 28 Jun 2025 06:23:18 -0400 Subject: [PATCH] tape: Encoder inherits bufio.Writer, need to do same for decoder --- tape/encode.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tape/encode.go b/tape/encode.go index 19f9379..24f12e4 100644 --- a/tape/encode.go +++ b/tape/encode.go @@ -2,6 +2,7 @@ package tape import "io" import "math" +import "bufio" // Encodable is any type that can write itself to an encoder. type Encodable interface { @@ -10,14 +11,16 @@ type Encodable interface { 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 { - io.Writer + bufio.Writer } -// WriteByte encodes a single byte to the output writer. -func (this *Encoder) WriteByte(value byte) (n int, err error) { - return this.WriteByte(uint8(value)) +// NewEncoder creates a new encoder that writes to writer. +func NewEncoder(writer io.Writer) *Encoder { + encoder := &Encoder { } + encoder.Reset(writer) + return encoder } // WriteInt8 encodes an 8-bit signed integer to the output writer.