agronholm / agronholm/cbor2

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

未關閉
#266 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
enhancement
主要語言
Rust
星號
305
分支
79
平均合併
21 小時 59 分鐘
30 天內合併 PR
2

描述

### 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().

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。