cbor_py icon indicating copy to clipboard operation
cbor_py copied to clipboard

Support variable length list encoding.

Open yihuang opened this issue 7 years ago • 4 comments

When cooperate with other language, I need to use encoding list with variable length encoding, currently we don't have a way to do this. I have two approaches in mind: 1、Encode tuple with fixed length encoding, encode list with variable length encoding. 2、Add a special class VarList which is inherited from list, and is encoded with variable length encoding.

What do you think?

yihuang avatar Jul 13 '18 11:07 yihuang

From my perspective, variable length encoding is for Python iterators without the data structure size knowledge.

asvetlov avatar Jul 13 '18 11:07 asvetlov

My situation is that I need to communicate between python and Haskell with cbor, the Haskell implementation use variable length encoding to encode List. So I just want to have this option.

yihuang avatar Jul 13 '18 15:07 yihuang

I've implemented the option 2 in my fork, only the pure python version though.

yihuang avatar Jul 13 '18 16:07 yihuang

From my perspective, variable length encoding is for Python iterators without the data structure size knowledge.

I think we don't have a way to detect directly if an object is an iterator without size knowledge, but with new VarList class, we can wrap any iterator in it like VarList(iterator_without_size). So user has the opportunity to decide which encoding they want. This feature is fully implemented in both python and c version, already tested for a while, really hope this can be merged.

yihuang avatar Nov 03 '18 05:11 yihuang