From 477e56d3592fd0e81fccb3d8b65e409cfa539f95 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 24 Jun 2025 14:37:45 -0400 Subject: [PATCH] tape: Add String method to Tag --- tape/tag.go | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/tape/tag.go b/tape/tag.go index 4e9db37..b32898d 100644 --- a/tape/tag.go +++ b/tape/tag.go @@ -1,16 +1,18 @@ package tape +import "fmt" + type Tag byte; const ( - SI Tag = 0 << 5 // Small integer - LI Tag = 1 << 5 // Large integer - FP Tag = 2 << 5 // Floating point - SBA Tag = 3 << 5 // Small byte array - LBA Tag = 4 << 5 // Large byte array - OTA Tag = 5 << 5 // One-tag array - KTV Tag = 6 << 5 // Key-tag-value table - TNMask Tag = 0xE0 // The entire TN bitfield - CNMask Tag = 0x20 // The entire CN bitfield - CNLimit Tag = 32 // All valid CNs are < CNLimit + SI Tag = 0 << 5 // Small integer + LI Tag = 1 << 5 // Large integer + FP Tag = 2 << 5 // Floating point + SBA Tag = 3 << 5 // Small byte array + LBA Tag = 4 << 5 // Large byte array + OTA Tag = 5 << 5 // One-tag array + KTV Tag = 6 << 5 // Key-tag-value table + TNMask Tag = 0xE0 // The entire TN bitfield + CNMask Tag = 0x1F // The entire CN bitfield + CNLimit Tag = 32 // All valid CNs are < CNLimit ) func (tag Tag) TN() int { @@ -33,6 +35,20 @@ func (tag Tag) Is(other Tag) bool { return tag.TN() == other.TN() } +func (tag Tag) String() string { + tn := fmt.Sprint(tag.TN()) + switch tag.WithoutCN() { + case SI: tn = "SI" + case LI: tn = "LI" + case FP: tn = "FP" + case SBA: tn = "SBA" + case LBA: tn = "LBA" + case OTA: tn = "OTA" + case KTV: tn = "KTV" + } + return fmt.Sprintf("%s:%d", tn, tag.CN()) +} + // BufferTag returns the appropriate tag for a buffer. func BufferTag(value []byte) Tag { return bufferLenTag(len(value))