diff --git a/internal/cbor/types.go b/internal/cbor/types.go index 49316aa..6f53832 100644 --- a/internal/cbor/types.go +++ b/internal/cbor/types.go @@ -4,6 +4,7 @@ import ( "fmt" "math" "net" + "reflect" ) // AppendNil inserts a 'Nil' object into the dst byte array. @@ -438,6 +439,14 @@ func (e Encoder) AppendInterface(dst []byte, i interface{}) []byte { return AppendEmbeddedJSON(dst, marshaled) } +// AppendType appends the parameter type (as a string) to the input byte slice. +func (e Encoder) AppendType(dst []byte, i interface{}) []byte { + if i == nil { + return e.AppendString(dst, "") + } + return e.AppendString(dst, reflect.TypeOf(i).String()) +} + // AppendIPAddr encodes and inserts an IP Address (IPv4 or IPv6). func (e Encoder) AppendIPAddr(dst []byte, ip net.IP) []byte { dst = append(dst, majorTypeTags|additionalTypeIntUint16)