Skip to content

Commit fa9bf37

Browse files
committed
Fix missing cbor encoder AppendType method
1 parent db22191 commit fa9bf37

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

internal/cbor/types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"math"
66
"net"
7+
"reflect"
78
)
89

910
// AppendNil inserts a 'Nil' object into the dst byte array.
@@ -438,6 +439,14 @@ func (e Encoder) AppendInterface(dst []byte, i interface{}) []byte {
438439
return AppendEmbeddedJSON(dst, marshaled)
439440
}
440441

442+
// AppendType appends the parameter type (as a string) to the input byte slice.
443+
func (e Encoder) AppendType(dst []byte, i interface{}) []byte {
444+
if i == nil {
445+
return e.AppendString(dst, "<nil>")
446+
}
447+
return e.AppendString(dst, reflect.TypeOf(i).String())
448+
}
449+
441450
// AppendIPAddr encodes and inserts an IP Address (IPv4 or IPv6).
442451
func (e Encoder) AppendIPAddr(dst []byte, ip net.IP) []byte {
443452
dst = append(dst, majorTypeTags|additionalTypeIntUint16)

0 commit comments

Comments
 (0)