func (i *IE) ParseRecursive(b []byte) error {
	l := len(b)
	if l < 2 {
		return io.ErrUnexpectedEOF
	}
	i.Tag = Tag(b[0])
	i.Length = b[1]
	if int(i.Length)+2 > len(b) {
		return nil
	}
	i.Value = b[2 : 2+int(i.Length)]
	if i.Tag.Form() == 1 {
		x, err := ParseAsBER(i.Value)
		if err != nil {
			return nil
		}
		i.IE = append(i.IE, x...)
	}
	return nil
}
ParseRecursive sets the values retrieved from byte sequence in an IE.
package tcap
import (
	"fmt"
	"io"
)
type Tag uint8
const (
	Universal int = iota
	ApplicationWide
	ContextSpecific
	Private
)
const (
	Primitive int = iota
	Constructor
)
func NewTag(cls, form, code int) Tag {
	return Tag((cls << 6) | (form << 5) | code)
}
func NewUniversalPrimitiveTag(code int) Tag {
	return NewTag(Universal, Primitive, code)
}
func NewUniversalConstructorTag(code int) Tag {
	return NewTag(Universal, Constructor, code)
}
func NewApplicationWidePrimitiveTag(code int) Tag {
	return NewTag(ApplicationWide, Primitive, code)
}
func NewApplicationWideConstructorTag(code int) Tag {
	return NewTag(ApplicationWide, Constructor, code)
}
func NewContextSpecificPrimitiveTag(code int) Tag {
	return NewTag(ContextSpecific, Primitive, code)
}
func NewContextSpecificConstructorTag(code int) Tag {
	return NewTag(ContextSpecific, Constructor, code)
}
func NewPrivatePrimitiveTag(code int) Tag {
	return NewTag(Private, Primitive, code)
}
func NewPrivateConstructorTag(code int) Tag {
	return NewTag(Private, Constructor, code)
}
func (t Tag) Class() int {
	return int(t) >> 6 & 0x3
}
func (t Tag) Form() int {
	return int(t) >> 5 & 0x1
}
func (t Tag) Code() int {
	return int(t) & 0x1f
}
type IE struct {
	Tag
	Length uint8
	Value  []byte
	IE     []*IE
}
func NewIE(tag Tag, value []byte) *IE {
	i := &IE{
		Tag:   tag,
		Value: value,
	}
	i.SetLength()
	return i
}
func (i *IE) MarshalBinary() ([]byte, error) {
	b := make([]byte, i.MarshalLen())
	if err := i.MarshalTo(b); err != nil {
		return nil, err
	}
	return b, nil
}
func (i *IE) MarshalTo(b []byte) error {
	if len(b) < 2 {
		return io.ErrUnexpectedEOF
	}
	b[0] = uint8(i.Tag)
	b[1] = i.Length
	copy(b[2:i.MarshalLen()], i.Value)
	return nil
}
func ParseMultiIEs(b []byte) ([]*IE, error) {
	var ies []*IE
	for {
		if len(b) == 0 {
			break
		}
		i, err := ParseIE(b)
		if err != nil {
			return nil, err
		}
		ies = append(ies, i)
		b = b[i.MarshalLen():]
		continue
	}
	return ies, nil
}
func ParseIE(b []byte) (*IE, error) {
	i := &IE{}
	if err := i.UnmarshalBinary(b); err != nil {
		return nil, err
	}
	return i, nil
}
func (i *IE) UnmarshalBinary(b []byte) error {
	l := len(b)
	if l < 3 {
		return io.ErrUnexpectedEOF
	}
	i.Tag = Tag(b[0])
	i.Length = b[1]
	if l < 2+int(i.Length) {
		return io.ErrUnexpectedEOF
	}
	i.Value = b[2 : 2+int(i.Length)]
	return nil
}
func ParseAsBer(b []byte) ([]*IE, error) {
	return ParseAsBER(b)
}
func ParseAsBER(b []byte) ([]*IE, error) {
	var ies []*IE
	for {
		if len(b) == 0 {
			break
		}
		i, err := ParseIERecursive(b)
		if err != nil {
			return nil, err
		}
		ies = append(ies, i)
		if len(i.IE) == 0 {
			b = b[i.MarshalLen():]
			continue
		}
		if i.IE[0].MarshalLen() < i.MarshalLen()-2 {
			var l = 2
			for _, ie := range i.IE {
				l += ie.MarshalLen()
			}
			b = b[l:]
			continue
		}
		b = b[i.MarshalLen():]
	}
	return ies, nil
}
func ParseIERecursive(b []byte) (*IE, error) {
	i := &IE{}
	if err := i.ParseRecursive(b); err != nil {
		return nil, err
	}
	return i, nil
}