aboutsummaryrefslogtreecommitdiff
path: root/ber/class.go
diff options
context:
space:
mode:
Diffstat (limited to 'ber/class.go')
-rw-r--r--ber/class.go31
1 files changed, 14 insertions, 17 deletions
diff --git a/ber/class.go b/ber/class.go
index ab455f1..32c1564 100644
--- a/ber/class.go
+++ b/ber/class.go
@@ -1,8 +1,14 @@
package ber
-import "io"
+import "fmt"
-type Class byte
+type Header struct {
+ Class
+ Kind
+ Tag
+}
+
+type Class int
const (
classUniversal Class = iota << 6
@@ -21,7 +27,7 @@ var classNames = map[Class]string{
func (c Class) String() string { return classNames[c] }
-type Kind byte
+type Kind int
const (
kindPrimitive Kind = iota << 5
@@ -107,19 +113,10 @@ var tagNames = map[Tag]string{
func (t Tag) String() string { return tagNames[t] }
-func Ident(r io.ByteReader) (Class, Kind, Tag) {
- b, _ := r.ReadByte()
- c := Class(b) & classMask
- k := Kind(b) & kindMask
- t := Tag(b) & tagMask
- if t == tagMask {
- t = Tag(Debase128(r))
+func (h Header) String() string {
+ f := "%v %v %v"
+ if h.Class != classUniversal {
+ f = "%v %v %d"
}
- return c, k, t
-}
-
-func MarshalClass(c Class, k Kind, t Tag) []byte {
- tag := base128(int(t))
- tag[0] |= byte(c) | byte(k)
- return tag
+ return fmt.Sprintf(f, h.Class, h.Kind, h.Tag)
}