Skip to main content

受 Java ByteBuffer 启发的字节操作库

项目描述

PyByteBuffer

Java nio ByteBuffer启发的用于操作缓冲区的库

>> 文件

设置

pip3 install PyByteBuffer

用法

from PyByteBuffer import ByteBuffer

buf = ByteBuffer.allocate(50)
# write byte 0x10 and increment position by 1
buf.put(0x10)
buf.put([0xcc, 0xdd, 0xee])
buf.put('something')
buf.put(bytes([00] * 4))

# endianness
buf.put(123456, 'little')
buf.put(1234561434234234, 'big')

# read 1 byte and increment position by 1
value = buf.get(1)
# read 10 bytes little endian and increment position by 10
value = buf.get(10, 'little')

# other allocations
buf = ByteBuffer.from_hex('deadbeef')
buf = ByteBuffer.wrap(bytes())

关于演出

我们在这个库中可以做的性能分析都是围绕int->bytes bytes<-int之间的转换。

使用 python3 内置 api int.to_bytes/from_bytes、struct pack/unpack 和stackoverflow中发布的“原始”解决方案进行了 1/100/500/1000 转换循环测试

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

PyByteBuffer-1.0.5.tar.gz (3.9 kB 查看哈希

已上传 source

内置分布

PyByteBuffer-1.0.5-py3-none-any.whl (5.2 kB 查看哈希

已上传 py3