package ber import "fmt" func Dump(b []byte) string { return dump(b, 0) } func short(b []byte) string { if len(b) > 5 { return fmt.Sprint(b[:5], " ...") } return fmt.Sprint(b) } func dump(b []byte, indent int) (s string) { class, kind, tag, _, value, rest := Split(b) s += fmt.Sprintf("%*s", indent*2, "") switch class { case classUniversal: switch tag { case tagInteger: s += fmt.Sprintln(tag, UnmarshalInt(value)) case tagObjectIdentifier: s += fmt.Sprintln(tag, UnmarshalOID(value)) case tagBitString: s += fmt.Sprintln(tag, UnmarshalBitString(value), value) default: s += fmt.Sprintln(tag, kind, short(value)) } default: s += fmt.Sprintln(class, kind, byte(tag), short(value)) } if len(value) > 0 && kind != kindPrimitive { s += dump(value, indent+1) } if len(rest) > 0 { s += dump(rest, indent) } return }