Skip to content

Commit

Permalink
Fix missing cbor encoder AppendType method
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Jan 25, 2023
1 parent db22191 commit fa9bf37
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/cbor/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math"
"net"
"reflect"
)

// AppendNil inserts a 'Nil' object into the dst byte array.
Expand Down Expand Up @@ -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, "<nil>")
}
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)
Expand Down

0 comments on commit fa9bf37

Please sign in to comment.