Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cbor/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ func (v *Value) processArray(data []byte) error {
func generateAstJson(obj interface{}) ([]byte, error) {
tmpJsonObj := map[string]interface{}{}
switch v := obj.(type) {
case []byte:
tmpJsonObj["bytes"] = hex.EncodeToString(v)
case ByteString:
tmpJsonObj["bytes"] = hex.EncodeToString(v.Bytes())
case WrappedCbor:
Expand Down
12 changes: 12 additions & 0 deletions cbor/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ var testDefs = []struct {
),
expectedAstJson: `{"map":[{"k":{"int":1},"v":{"int":2}},{"k":{"int":3},"v":{"int":4}}]}`,
},
// 259({2: [h'abcd']})
{
cborHex: "D90103A1028142ABCD",
expectedObject: cbor.Map(
map[any]any{
uint64(2): []any{
[]byte{0xab, 0xcd},
},
},
),
expectedAstJson: `{"map":[{"k":{"int":2},"v":{"list":[{"bytes":"abcd"}]}}]}`,
},
}

func TestValueDecode(t *testing.T) {
Expand Down