From 54caa4e7e085e177ff05b719ae247d21fe8c257e Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 26 Sep 2015 12:04:34 +0200 Subject: Replace with new implementation --- ber/class.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'ber/class.go') 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) } -- cgit v1.2.3