import struct


def pack_uint_bytes(val: int) -> bytes:
    """
    Pack an non-negative integer value into bytes

    :param val: the integer.
    :return: the buffer.
    """
    if val <= 0xFF:
        return struct.pack('!B', val)
    elif val <= 0xFFFF:
        return struct.pack('!H', val)
    elif val <= 0xFFFFFFFF:
        return struct.pack('!I', val)
    else:
        return struct.pack('!Q', val)