How to use the quarry.types.buffer.Buffer function in quarry

To help you get started, we’ve selected a few quarry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_read():
    buffer = Buffer()
    buffer.add(b"spam")
    assert buffer.read(2) == b"sp"
    assert buffer.read(2) == b"am"
    buffer.add(b"eggs")
    assert buffer.read() == b"eggs"
    with pytest.raises(BufferUnderrun):
        buffer.read(1)
github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_unpack_string():
    buffer = Buffer()
    buffer.add(b"\x04spam")
    assert buffer.unpack_string() == "spam"
github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_unpack_chat():
    buffer = Buffer()
    buffer.add(b'\x11["spam", " eggs"]')
    assert buffer.unpack_chat().to_string() == "spam eggs"
    buffer.add(b'\x22{"text": "spam", "extra": " eggs"}')
    assert buffer.unpack_chat().to_string() == "spam eggs"
    buffer.add(b'\x14{"translate": "foo"}')
    assert buffer.unpack_chat().to_string() == "foo"
    buffer.add(b'\x2E{"translate": "foo", "with": ["spam", "eggs"]}')
    assert buffer.unpack_chat().to_string() == "foo{spam, eggs}"
github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_unpack_uuid():
    buffer = Buffer()
    buffer.add(uuid_vector)
    assert buffer.unpack_uuid().to_bytes() == uuid_vector
github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_add():
    buffer = Buffer()
    buffer.add(b"spam")
    assert len(buffer) == 4
    assert buffer.read() == b"spam"
github barneygale / quarry / quarry / types / nbt.py View on Github external
def load_chunk(self, chunk_x, chunk_z):
        """
        Loads the chunk at the given co-ordinates from the region file.
        The co-ordinates should range from 0 to 31. Returns a ``TagRoot``.
        """

        buff = Buffer()

        # Read extent header
        self.fd.seek(4 * (32 * chunk_z + chunk_x))
        buff.add(self.fd.read(4))
        entry = buff.unpack('I')
        chunk_offset, chunk_length = entry >> 8, entry & 0xFF
        if chunk_offset == 0:
            raise ValueError((chunk_x, chunk_z))

        # Read chunk
        self.fd.seek(4096 * chunk_offset)
        buff.add(self.fd.read(4096 * chunk_length))
        chunk = buff.read(buff.unpack('IB')[0])
        chunk = zlib.decompress(chunk)
        chunk = TagRoot.from_bytes(chunk)
        return chunk
github barneygale / quarry / quarry / types / nbt.py View on Github external
def from_bytes(cls, bytes):
        return cls.from_buff(Buffer(bytes))