From fa9bf3742aed687ca8f7d1c73cb834ab68521697 Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Wed, 25 Jan 2023 17:34:40 +0100 Subject: [PATCH] Fix missing cbor encoder AppendType method --- internal/cbor/types.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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)