Пример #1
0
def export_bin(output_file, code_blocks, multiplicity=1):
    if multiplicity < 1:
        raise ValueError(f"Multiplicity {multiplicity} is less than one")
    #if len(code_blocks) != 1:
    #    raise ValueError("Can only export bin for single code block")
    code = ContiguousBytes(code_blocks, default=0x00)
    logging.info(
        f"Export from address 0x{code.start:04X} to 0x{code.stop - 1:04X}")
    for _ in range(multiplicity):
        output_file.write(code.to_bytes())
    logging.info(
        f"Wrote {len(code) * multiplicity} (0x{len(code) * multiplicity:04X}) bytes"
    )
Пример #2
0
def test_iteration_over_separated_blocks_respects_default():
    blocks = {5: b'Hello', 12: b", World!"}
    cb = ContiguousBytes(blocks, default=0xff)
    whole = cb.to_bytes()
    assert whole == b'Hello\xff\xff, World!'
Пример #3
0
def test_iteration_after_last_block():
    blocks = {5: b'Hello', 12: b", World!"}
    cb = ContiguousBytes(blocks, stop=23)
    whole = cb.to_bytes()
    assert whole == b'Hello\x00\x00, World!\x00\x00\x00'
Пример #4
0
def test_iteration_over_separated_blocks():
    blocks = {5: b'Hello', 12: b", World!"}
    cb = ContiguousBytes(blocks)
    whole = cb.to_bytes()
    assert whole == b'Hello\x00\x00, World!'
Пример #5
0
def test_iteration_before_first_block():
    blocks = {5: b'Hello', 12: b", World!"}
    cb = ContiguousBytes(blocks, start=0)
    whole = cb.to_bytes()
    assert whole == b'\x00\x00\x00\x00\x00Hello\x00\x00, World!'