From 7b8240cec6c0925a98937c8b22cfbede68e17e28 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 21 Jun 2025 19:26:15 -0400 Subject: [PATCH] tape: Add tag functions to the encoder --- tape/decode.go | 7 +++++++ tape/encode.go | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/tape/decode.go b/tape/decode.go index bcf3fd1..990418b 100644 --- a/tape/decode.go +++ b/tape/decode.go @@ -140,3 +140,10 @@ func (this *Decoder) ReadFloat64() (value float64, n int, err error) { n += nn; if err != nil { return 0, n, err } return math.Float64frombits(bits), n, nil } + +// ReadTag decodes a [Tag] from the input reader. +func (this *Decoder) ReadTag() (value Tag, n int, err error) { + uncasted, nn, err := this.ReadUint8() + n += nn; if err != nil { return 0, n, err } + return Tag(uncasted), n, nil +} diff --git a/tape/encode.go b/tape/encode.go index b84c70f..878697a 100644 --- a/tape/encode.go +++ b/tape/encode.go @@ -129,3 +129,8 @@ func (this *Encoder) WriteFloat32(value float32) (n int, err error) { func (this *Encoder) WriteFloat64(value float64) (n int, err error) { return this.WriteUint64(math.Float64bits(value)) } + +// WriteTag encodes a [Tag] to the output writer. +func (this *Encoder) WriteTag(value Tag) (n int, err error) { + return this.WriteUint8(uint8(value)) +}