diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2015-09-26 12:04:34 +0200 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2015-09-26 12:04:34 +0200 |
commit | 54caa4e7e085e177ff05b719ae247d21fe8c257e (patch) | |
tree | 363400fe1c6c1e7b696c72caaabc4882756355fa /ber/class.go | |
parent | 1fcefc99a82bac6ce725b6f11277e4aa291a7f51 (diff) |
Replace with new implementation
Diffstat (limited to 'ber/class.go')
-rw-r--r-- | ber/class.go | 31 |
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) } |