tape: Add String method to Tag
This commit is contained in:
parent
e3487d26a1
commit
477e56d359
18
tape/tag.go
18
tape/tag.go
@ -1,5 +1,7 @@
|
|||||||
package tape
|
package tape
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
type Tag byte; const (
|
type Tag byte; const (
|
||||||
SI Tag = 0 << 5 // Small integer
|
SI Tag = 0 << 5 // Small integer
|
||||||
LI Tag = 1 << 5 // Large integer
|
LI Tag = 1 << 5 // Large integer
|
||||||
@ -9,7 +11,7 @@ type Tag byte; const (
|
|||||||
OTA Tag = 5 << 5 // One-tag array
|
OTA Tag = 5 << 5 // One-tag array
|
||||||
KTV Tag = 6 << 5 // Key-tag-value table
|
KTV Tag = 6 << 5 // Key-tag-value table
|
||||||
TNMask Tag = 0xE0 // The entire TN bitfield
|
TNMask Tag = 0xE0 // The entire TN bitfield
|
||||||
CNMask Tag = 0x20 // The entire CN bitfield
|
CNMask Tag = 0x1F // The entire CN bitfield
|
||||||
CNLimit Tag = 32 // All valid CNs are < CNLimit
|
CNLimit Tag = 32 // All valid CNs are < CNLimit
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,6 +35,20 @@ func (tag Tag) Is(other Tag) bool {
|
|||||||
return tag.TN() == other.TN()
|
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.
|
// BufferTag returns the appropriate tag for a buffer.
|
||||||
func BufferTag(value []byte) Tag {
|
func BufferTag(value []byte) Tag {
|
||||||
return bufferLenTag(len(value))
|
return bufferLenTag(len(value))
|
||||||
|
Loading…
Reference in New Issue
Block a user