func (dec *Decoder) decodeBase16() []byte {
	major, _, err := dec.parser.parseInformation()
	checkErr(err)
	if major != cborByteString && major != cborTextString {
		panic(fmt.Errorf("expected string or bytes found %v", major))
	}
	data := dec.decodeBytes()
	return []byte(fmt.Sprintf("%x", data))
}
Decode a base16 string
package cbor
import (
	"encoding/base64"
	"errors"
	"fmt"
	"io"
	"math/big"
	"mime"
	"net/url"
	"reflect"
	"regexp"
	"time"
)
type handleDecFn func(*Decoder, reflect.Value) error
type extensionDecMap map[uintptr]handleDecFn
var extensionsDec extensionDecMap = make(extensionDecMap)
func (e *extensionDecMap) register(t reflect.Type, fn handleDecFn) error {
	tid := reflect.ValueOf(t).Pointer()
	if _, ok := extensionsDec[tid]; ok {
		return fmt.Errorf("%s type is already registered\n", t)
	}
	extensionsDec[tid] = fn
	return nil
}
func (e *extensionDecMap) lookup(t reflect.Type) (handleDecFn, error) {
	tid := reflect.ValueOf(t).Pointer()
	fn, ok := extensionsDec[tid]
	if !ok {
		return nil, errors.New(fmt.Sprintf(
			"%s not matched as registered extension handler", t))
	}
	return fn, nil
}
func RegisterExtensionFn(t reflect.Type, fn handleDecFn) error {
	return extensionsDec.register(t, fn)
}
func LookupExtensionFn(t reflect.Type) (handleDecFn, error) {
	return extensionsDec.lookup(t)
}
type Decoder struct {
	parser *Parser
	strict bool
}
func NewDecoder(r io.Reader, options ...func(*Decoder)) *Decoder {
	d := &Decoder{parser: &Parser{r: r}, strict: false}
	if len(options) > 0 {
		for _, option := range options {
			option(d)
		}
	}
	return d
}
func (dec *Decoder) Decode(v interface{}) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = r.(error)
		}
	}()
	var info byte
	var major Major
	major, info, err = dec.parser.parseInformation()
	if err != nil {
		return err
	}
	if err = dec.checkTypes(reflect.TypeOf(v), major, info); err != nil {
		return err
	}
	switch t := v.(type) {
	case nil:
		return errors.New("can't decode a value into nil")
	case *uint8:
		*t = dec.decodeUint8()
	case *int8:
		*t = dec.decodeInt8()
	case *uint16:
		*t = dec.decodeUint16()
	case *int16:
		*t = dec.decodeInt16()
	case *uint32:
		*t = dec.decodeUint32()
	case *int32:
		*t = dec.decodeInt32()
	case *uint64:
		*t = dec.decodeUint64()
	case *int64:
		*t = dec.decodeInt64()
	case *float16:
		*t = dec.decodeFloat16()
	case *float32:
		if major == cborNC {
			*t = dec.decodeFloat32()
		} else {
			*t = dec.decodeDecimalFraction()
		}
	case *float64:
		*t = dec.decodeFloat64()
	case *big.Int:
		if v.(*big.Int).Sign() < 0 {
			n := dec.decodeNegativeBigNum()
			*t = *n.Neg(n)
		} else {
			n := dec.decodePositiveBigNum()
			*t = *n
		}
	case *time.Time:
		func() {
			defer func() {
				if r := recover(); r != nil {
					*t = dec.decodeEpochDateTime(struct{}{})
				}
			}()
			*t = dec.decodeStringDateTime()
		}()
	case *big.Rat:
		n := dec.decodeBigFloat()
		*t = *n
	case *[]byte:
		*t = dec.decodeBytes()
	case *string:
		*t = dec.decodeString()
	case *bool:
		*t = dec.decodeBool()
	case *interface{}:
		return dec.decode(reflect.ValueOf(v).Elem())
	case reflect.Value:
		return dec.decode(t.Elem())
	default:
		rv := reflect.ValueOf(v)
		if rv.Kind() == reflect.Ptr && !rv.IsNil() || !rv.IsValid() {
			return dec.decode(rv.Elem())
		}
		return &InvalidDecodeError{rv.Type()}
	}
	return err
}
func (dec *Decoder) decode(rv reflect.Value) (err error) {
	if dec.parser.isNil() || dec.parser.isUndef() {
		if rv.Kind() == reflect.Ptr {
			if !rv.IsNil() {
				rv.Set(reflect.Zero(rv.Type()))
			}
			return nil
		}
		if rv.IsValid() && rv.CanSet() {
			rv.Set(reflect.Zero(rv.Type()))
		}
		return nil
	}
	var handler handleDecFn
	handler, err = dec.lookupFn(rv)
	if err != nil {
		return err
	}
	defer func() {
		if r := recover(); r != nil {
			err = errors.New(fmt.Sprint(r))
		}
	}()
	return handler(dec, rv)
}
func (dec *Decoder) lookupFn(rv reflect.Value) (handler handleDecFn, e error) {
	rk := rv.Kind()
	switch rk {
	case reflect.Map:
		handler = (*Decoder).decodekMap
	case reflect.Struct:
		handler = (*Decoder).decodekStruct
	case reflect.Interface:
		handler = (*Decoder).decodekInterface
	case reflect.String:
		handler = (*Decoder).decodekString
	case reflect.Int:
		handler = (*Decoder).decodekInt
	case reflect.Int8:
		handler = (*Decoder).decodekInt8
	case reflect.Int16:
		handler = (*Decoder).decodekInt16
	case reflect.Int32:
		handler = (*Decoder).decodekInt32
	case reflect.Int64:
		handler = (*Decoder).decodekInt64
	case reflect.Uint:
		handler = (*Decoder).decodekUint
	case reflect.Uint8:
		handler = (*Decoder).decodekUint8
	case reflect.Uint16:
		handler = (*Decoder).decodekUint16
	case reflect.Uint32:
		handler = (*Decoder).decodekUint32
	case reflect.Uint64:
		handler = (*Decoder).decodekUint64
	case reflect.Bool:
		handler = (*Decoder).decodekBool
	case reflect.Float32:
		handler = (*Decoder).decodekFloat32
	case reflect.Float64:
		handler = (*Decoder).decodekFloat64
	case reflect.Slice:
		handler = (*Decoder).decodekSlice
	case reflect.Array:
		handler = (*Decoder).decodekArray
	default:
		handler, e = LookupExtensionFn(rv.Type())
	}
	return handler, e
}
func (dec *Decoder) checkTypes(t reflect.Type, major Major, info byte) error {
	if major == cborTag || major == cborDataArray || major == cborDataMap || t == reflect.TypeOf(reflect.Value{}) {
		return nil
	}
	msg := "expected %s, got %s (major %d, info %d [%#v])\n"
	e, ok := expectedTypesMap[major][info]
	if !ok {
		switch major {
		case cborUnsignedInt:
			if info <= cborSmallInt {
				e = reflect.PtrTo(reflect.TypeOf(uint8(0)))
				break
			}
			return errors.New(fmt.Sprintf("Unknown info %d for major 1", info))
		case cborByteString:
			if info <= cborSmallInt || info == cborIndefinite {
				e = reflect.TypeOf([]byte{})
				break
			}
			return errors.New(fmt.Sprintf("Unknown info %d for major 2", info))
		case cborTextString:
			if info <= cborSmallInt || info == cborIndefinite {
				e = reflect.TypeOf("")
				break
			}
			return errors.New(fmt.Sprintf("Unknown info %d for major 3", info))
		case cborNC:
			if info == cborFalse || info == cborTrue {
				e = reflect.TypeOf(false)
				break
			}
			if info == cborNil || info == cborUndef {
				e = reflect.TypeOf(reflect.Interface)
				break
			}
			return errors.New(fmt.Sprintf("Unknown info %d for major 7", info))
		}
	}
	e = reflect.PtrTo(e)
	header := byte((major << 5)) | info
	if e != t {
		return errors.New(fmt.Sprintf(msg, t, e, major, info, header))
	}
	return nil
}
func (dec *Decoder) decodeUint() uint64 {
	return dec.parser.buflen()
}
func (dec *Decoder) decodeInt() int64 {
	return ^int64(dec.parser.buflen())
}
func (dec *Decoder) decodeUint8() uint8 {
	return dec.parser.parseUint8()
}
func (dec *Decoder) decodeUint16() uint16 {
	return dec.parser.parseUint16()
}
func (dec *Decoder) decodeUint32() uint32 {
	return dec.parser.parseUint32()
}
func (dec *Decoder) decodeUint64() uint64 {
	return dec.parser.parseUint64()
}
func (dec *Decoder) decodeInt8() int8 {
	return int8(^dec.decodeUint8())
}
func (dec *Decoder) decodeInt16() int16 {
	return int16(^dec.decodeUint16())
}
func (dec *Decoder) decodeInt32() int32 {
	return int32(^dec.decodeUint32())
}
func (dec *Decoder) decodeInt64() int64 {
	return int64(^dec.decodeUint64())
}
func (dec *Decoder) decodeFloat16() float16 {
	return dec.parser.parseFloat16()
}
func (dec *Decoder) decodeFloat32() float32 {
	return dec.parser.parseFloat32()
}
func (dec *Decoder) decodeFloat64() float64 {
	return dec.parser.parseFloat64()
}
func (dec *Decoder) decodeStringDateTime() time.Time {
	major, _, err := dec.parser.parseInformation()
	checkErr(err)
	if major != cborTextString {
		panic(fmt.Errorf("expected UTF-8 string, found %v", major))
	}
	t, err := time.Parse(time.RFC3339, dec.decodeString())
	checkErr(err)
	return t
}
func (dec *Decoder) decodeEpochDateTime(parseInforamtion ...struct{}) time.Time {
	var err error
	var major Major
	if len(parseInforamtion) == 0 {
		major, _, err = dec.parser.parseInformation()
		checkErr(err)
	} else {
		major, _ = dec.parser.parseHeader()
	}
	var n int64
	switch major {
	case cborUnsignedInt:
		n = int64(dec.decodeUint())
	case cborNegativeInt:
		n = dec.decodeInt()
	default:
		switch dec.parser.header {
		case absoluteFloat16:
			n = int64(int(dec.decodeFloat16()))
		case absoluteFloat32:
			n = int64(int(dec.decodeFloat32()))
		case absoluteFloat64:
			n = int64(int(dec.decodeFloat64()))
		default:
			panic(fmt.Errorf("can't decode Epoch timestamp %v", major))
		}
	}
	return time.Unix(n, int64(0))
}
func (dec *Decoder) decodeDecimalFraction() float32 {
	major, _, err := dec.parser.parseInformation()
	checkErr(err)
	if major != cborDataArray {
		panic(fmt.Errorf("Decimal Fraction must be represented as an array of two elements"))
	}
	major, _, err = dec.parser.parseInformation()
	checkErr(err)
	if major > cborNegativeInt {
		panic(fmt.Errorf("Can't decode %s as decimal fraction exponent", major))
	}
	e := dec.decodeInt()
	major, _, err = dec.parser.parseInformation()
	checkErr(err)
	if major > cborNegativeInt {
		panic(fmt.Errorf("Can't decode %s as decimal fraction mantissa", major))
	}
	var m int64
	if major == cborUnsignedInt {
		m = int64(dec.decodeUint())
	} else {
		m = dec.decodeInt()
	}
	return decimalFractionToFloat(m, e)
}
func (dec *Decoder) decodeBigFloat() *big.Rat {
	major, _, err := dec.parser.parseInformation()
	checkErr(err)
	if major != cborDataArray {
		panic("Big float must be represented as an array of two elements")
	}
	major, _, err = dec.parser.parseInformation()
	checkErr(err)
	if major > cborNegativeInt {
		panic(fmt.Errorf("Can't decode %s as decimal fraction exponent", major))
	}
	e := dec.decodeInt()
	major, info, err := dec.parser.parseInformation()
	checkErr(err)
	if major > cborNegativeInt && (major != cborTag && info != cborBigNum) {
		panic(fmt.Errorf("Can't decode %s as decimal fraction mantissa", major))
	}
	switch major {
	case cborUnsignedInt:
		m := int64(dec.decodeUint())
		return bigFloatToRatFromInt64(m, e)
	case cborNegativeInt:
		m := int64(dec.decodeInt())
		return bigFloatToRatFromInt64(m, e)
	case cborTag:
		m := dec.decodePositiveBigNum()
		return bigFloatToRatFromBigInt(m, e)
	}
	return big.NewRat(0, 0)
}
func (dec *Decoder) decodePositiveBigNum() *big.Int {
	major, _, err := dec.parser.parseInformation()
	checkErr(err)
	if major != cborByteString {
		panic(fmt.Errorf("expected bytes found %v", major))
	}
	i := new(big.Int)
	i.SetBytes(dec.decodeBytes())
	return i
}
func (dec *Decoder) decodeNegativeBigNum() *big.Int {
	major, _, err := dec.parser.parseInformation()
	checkErr(err)
	if major != cborByteString {
		panic(fmt.Errorf("expected bytes found %v", major))
	}
	i := new(big.Int)
	i.SetBytes(dec.decodeBytes())
	return i.Add(i, big.NewInt(1))
}
func (dec *Decoder) decodeBase64Url() []byte {
	major, _, err := dec.parser.parseInformation()
	checkErr(err)
	if major != cborByteString && major != cborTextString {
		panic(fmt.Errorf("expected string or bytes found %v", major))
	}
	data := dec.decodeBytes()
	var buf []byte = make([]byte, base64.URLEncoding.EncodedLen(len(data)))
	base64.URLEncoding.Encode(buf, data)
	return buf
}
func (dec *Decoder) decodeBase64() []byte {
	major, _, err := dec.parser.parseInformation()
	checkErr(err)
	if major != cborByteString && major != cborTextString {
		panic(fmt.Errorf("expected string or bytes found %v", major))
	}
	data := dec.decodeBytes()
	var buf []byte = make([]byte, base64.StdEncoding.EncodedLen(len(data)))
	base64.StdEncoding.Encode(buf, data)
	return buf
}