fxamacker / cbor

CBOR codec (RFC 8949) with CBOR tags, Go struct tags (toarray, keyasint, omitempty), float64/32/16, big.Int, and fuzz tested billions of execs.
MIT License
710 stars 59 forks source link

feature: ability to embed the map within the struct #272

Open 0xc1f opened 3 years ago

0xc1f commented 3 years ago

I'm working on the COSE library with built-in CWT support by using your powerful library. I would like to have the ability to embed the map keys (with their corresponding values) in to the parent struct definition (for example, by specific tag or the conditional mix of them). The idea is to keep the key type by using the specific tag (keyasint) within the parent structure on the anonymous embedded map type. PR's are welcome? :)

123

0xc1f commented 3 years ago

Currently, the embedded struct (within the parent struct) with a fields will also be encoded as a CBOR map. What if to involve a struct tag (for example, 'embed') which usage will trigger the inner fields (and kv of Go map as well) embedding of the target embedded struct to the parent struct on encoding?