Skip to main content

Wrapping non-continuous buffers in a late-resolving slice'able buffer-compatible object

Project description

memorywrapper

MemoryWrapper provides a slice-able front-end for a list of non-continuous memory backends, and only joins the needed area into a bytes object as needed.

It uses the new __buffer__ protocol that is implementable in python starting with python 3.12.

Installing

pip install memorywrapper

Using

    >>> from memorywrapper import MemoryWrapper
    >>> import struct
    >>> memory = MemoryWrapper([b"\x01\x02\x03", bytes([4,5,6])])
    >>> part = memory[1:-1]
    >>> (value,) = struct.unpack(">I", part)
    >>> f"0x{value:08x}"
    '0x02030405'

make_slices

make_slices provides a way to cut something like bytes, memoryview, or memorywrapper into equal-sized chunks.

    >>> from memorywrapper import make_slices
    >>> list(make_slices([1,2,3,4,5,6,7,8,9], 3))
    [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memorywrapper-0.0.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

memorywrapper-0.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file memorywrapper-0.0.1.tar.gz.

File metadata

  • Download URL: memorywrapper-0.0.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for memorywrapper-0.0.1.tar.gz
Algorithm Hash digest
SHA256 54299d3b0c104a76c467a91df55f164aa47329f6ec7a25101cd5c6b1fdfceb08
MD5 a18a4981ca309bb42f7eee857059df9e
BLAKE2b-256 3c6675a947f44cd04fcb37b898e6bc4e5e051fdd8b4fc16761a2f55723d772d4

See more details on using hashes here.

File details

Details for the file memorywrapper-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for memorywrapper-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f45600d9f5758723ce9489335c42c35462dc6eb81079aa2c8c60fae3e62629c
MD5 b4f0bacbd721ec5061b5f175abf2f245
BLAKE2b-256 660f51d3ba4249e8fe0881bc5fcca656374c473455e51f44000eba875e9b6292

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page