tape: Add String method to Tag
This commit is contained in:
parent
e3487d26a1
commit
477e56d359
36
tape/tag.go
36
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))
|
||||
|
Loading…
Reference in New Issue
Block a user