# Path: azmq/errors.py
# class ProtocolError(AZMQError):
#     def __init__(self, msg, fatal=False):
#         super().__init__(msg)
#         self.fatal = fatal


import struct
from .errors import ProtocolError
    for key, value in metadata.items():
        assert len(key) < 256
        assert len(value) < 2 ** 32
        results.extend([
            struct.pack('!B', len(key)),
            key,
            struct.pack('!I', len(value)),
            value,
        ])

    return results


def buffer_to_metadata(buffer):
    """
    Transform a buffer to a metadata dictionary.

    :param buffer: The buffer, as received in a READY command.
    :returns: A metadata dictionary, with its keys normalized (in
        lowercase).
    """
    offset = 0
    size = len(buffer)
    metadata = {}

    while offset < size:
        name_size = struct.unpack_from('B', buffer, offset)[0]
        offset += 1

        if name_size > size - 4:

# Path: azmq/errors.py
# class ProtocolError(AZMQError):
#     def __init__(self, msg, fatal=False):
#         super().__init__(msg)
#         self.fatal = fatal


# Path: azmq/metadata.py
import struct
from .errors import ProtocolError

    for key, value in metadata.items():
        assert len(key) < 256
        assert len(value) < 2 ** 32
        results.extend([
            struct.pack('!B', len(key)),
            key,
            struct.pack('!I', len(value)),
            value,
        ])

    return results


def buffer_to_metadata(buffer):
    """
    Transform a buffer to a metadata dictionary.

    :param buffer: The buffer, as received in a READY command.
    :returns: A metadata dictionary, with its keys normalized (in
        lowercase).
    """
    offset = 0
    size = len(buffer)
    metadata = {}

    while offset < size:
        name_size = struct.unpack_from('B', buffer, offset)[0]
        offset += 1

        if name_size > size - 4:

            raise ProtocolError(