Commit 5e2ba3a6 authored by aschmahmann's avatar aschmahmann Committed by Jakub Sztandera

Added a utility function to decode a CBOR blob into a printable string (#58)

* Added a utility function to decode a CBOR blob into a printable string

* Better naming for decode.go and DecodeCBOR

* Moved readable.go into the main cbornode package
parent fed7b4bc
package cbornode
import (
"bufio"
"bytes"
cbor "github.com/polydawn/refmt/cbor"
"github.com/polydawn/refmt/pretty"
"github.com/polydawn/refmt/shared"
)
//HumanReadable returns a string representation of a CBOR blob
func HumanReadable(blob []byte) (string, error) {
reader := bytes.NewReader(blob)
var buf bytes.Buffer
writer := bufio.NewWriter(&buf)
err := shared.TokenPump{
TokenSource: cbor.NewDecoder(cbor.DecodeOptions{}, reader),
TokenSink: pretty.NewEncoder(writer),
}.Run()
if err != nil {
return "", err
}
if err = writer.Flush(); err != nil {
return "", err
}
return buf.String(), nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment