aboutsummaryrefslogtreecommitdiff
path: root/ber/new/dump.go
blob: f3ba6728ffac23793380a761dcc700df6170e2a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package ber

import (
	"bytes"
	"fmt"
)

func Dump(b []byte) string {
	buf := bytes.NewBuffer(b)
	s := &state{*buf}
	return s.dump(0)
}

func (s *state) dump(ident int) string {
	if s.Len() == 0 {
		return ""
	}
	h := s.ident()
	fmt.Printf("%*s", 2*ident, "")
	fmt.Printf("%v %x\n", h, s.Bytes())
	if h.Kind == kindConstructed {
		return s.subState().dump(ident + 1)
	}
	switch h.Tag {
	case tagInteger:
		fmt.Println(h.Tag, s.unmarshalInt())
		// here be dragons
	}
	for s.Len() > 0 {
		s.dump(ident)
	}
	return ""
}