diff --git a/utils/cbor.go b/utils/cbor.go index c983ee50..4f8bf737 100644 --- a/utils/cbor.go +++ b/utils/cbor.go @@ -5,6 +5,7 @@ import ( "github.com/fxamacker/cbor/v2" ) +// CborEncode encodes the provided data as CBOR using the correct mode func CborEncode(data interface{}) ([]byte, error) { buf := bytes.NewBuffer(nil) em, err := cbor.CoreDetEncOptions().EncMode() @@ -16,6 +17,7 @@ func CborEncode(data interface{}) ([]byte, error) { return buf.Bytes(), err } +// CborDecode decodes the provided CBOR into the given destination func CborDecode(dataBytes []byte, dest interface{}) (int, error) { data := bytes.NewReader(dataBytes) dec := cbor.NewDecoder(data) diff --git a/utils/debug.go b/utils/debug.go index cdc9af66..293d254e 100644 --- a/utils/debug.go +++ b/utils/debug.go @@ -5,6 +5,7 @@ import ( "fmt" ) +// DumpCborStructure generates an indented string representing an arbitrary data structure for debugging purposes func DumpCborStructure(data interface{}, prefix string) string { var ret bytes.Buffer switch v := data.(type) { diff --git a/utils/utils.go b/utils/utils.go new file mode 100644 index 00000000..2b0aba35 --- /dev/null +++ b/utils/utils.go @@ -0,0 +1,2 @@ +// Package utils provides random utility functions +package utils