agronholm / agronholm/cbor2

Add option to decode type bytestring as a mutable bytearray rather than bytes

Aberta
#266 4 comentários 0 reações 0 responsáveis Ver no GitHub
enhancement
Linguagem predominante
Rust
Estrelas
305
Forks
79
Merge médio
21h 59min
PRs com merge (30d)
2

Descrição

### Things to check first

- [x] I have searched the existing issues and didn't find my feature already requested there

### Feature description

For performance reasons, it would be nice if there were an option / flag to decode cbor bytes strings (cbor type 2) as python bytearrays rather than bytes. This would allow the user to modify the buffer rather than do a memcpy first to convert it to a mutable type.

This change would actually eliminate two memcpys. The current implementation (I'm looking at decode.c decode_definite_long_bytestring()) copies the packet (in chunks) into a bytearray and then copies the bytearray to a bytes object before returning it. Then to get a mutable array, the user has to copy the bytes into a bytearray.
If the decode just returned the bytearray instead, that would remove two memcpys (bytearray -> bytes during decode, then bytes -> bytearray in python to make it mutable).

From looking through the issues, I think this might affect other use cases:
Issue #15
Issue #240
So maybe it would be best to make it an optional decode flag?

### Use case

My use case is receiving cbor packets that include large chunks of bytes (images). My end goal is to get a mutable numpy array using np.frombuffer().

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.