Exemplo n.º 1
0
def top_key_tuple_to_bytes(top_key_tuple, salt_byte=0):
    """ Returns a binary representation of top_key_tuple. """

    ret = struct.pack(BASE_FMT, HDR_BYTES, salt_byte,
                      len(top_key_tuple[0]), len(top_key_tuple[1]))
    for graph_chk in top_key_tuple[0]:
        ret += chk_to_bytes(graph_chk)

    # Can't find doc. True for all modern Python
    assert int(True) == 1 and int(False) == 0
    for update in top_key_tuple[1]:
        flags = (((int(update[4]) * 0xff) & HAS_PARENTS)
                 | ((int(update[5]) * 0xff) & HAS_HEADS))

        ret += struct.pack(BASE_UPDATE_FMT,
                           update[0], flags,
                           len(update[1]), len(update[2]),
                           len(update[3]))

        ret += versions_to_bytes(update[1]) # parents
        ret += versions_to_bytes(update[2]) # heads
        for chk in update[3]:
            chk_bytes = chk_to_bytes(chk)
            assert len(chk_bytes) == CHK_SIZE
            ret += chk_bytes

    return ret
Exemplo n.º 2
0
def top_key_tuple_to_bytes(top_key_tuple, salt_byte=0):
    """ Returns a binary representation of top_key_tuple. """

    ret = struct.pack(BASE_FMT, HDR_BYTES, salt_byte, len(top_key_tuple[0]),
                      len(top_key_tuple[1]))
    for graph_chk in top_key_tuple[0]:
        ret += chk_to_bytes(graph_chk)

    # Can't find doc. True for all modern Python
    assert int(True) == 1 and int(False) == 0
    for update in top_key_tuple[1]:
        flags = (((int(update[4]) * 0xff) & HAS_PARENTS)
                 | ((int(update[5]) * 0xff) & HAS_HEADS))

        ret += struct.pack(BASE_UPDATE_FMT, update[0], flags, len(update[1]),
                           len(update[2]), len(update[3]))

        ret += versions_to_bytes(update[1])  # parents
        ret += versions_to_bytes(update[2])  # heads
        for chk in update[3]:
            chk_bytes = chk_to_bytes(chk)
            assert len(chk_bytes) == CHK_SIZE
            ret += chk_bytes

    return ret
Exemplo n.º 3
0
def top_key_tuple_to_bytes(values, salt_byte=0):
    """ Reads the binary rep of an archive top key. """

    ret = struct.pack(BASE_FMT, HDR_BYTES, salt_byte, values[2],
                      len(values[0]), len(values[1]))

    for block in values[0]:
        ret += struct.pack(BLOCK_BASE_FMT, block[0], block[2], len(block[1]))
        for chk in block[1]:
            ret += chk_to_bytes(chk)

    for obj in values[1]:
        ret += struct.pack(ROOT_OBJ_FMT, obj[0], obj[1])
    return ret
Exemplo n.º 4
0
def top_key_tuple_to_bytes(values, salt_byte=0):
    """ Reads the binary rep of an archive top key. """

    ret = struct.pack(BASE_FMT, HDR_BYTES,
                      salt_byte,
                      values[2],
                      len(values[0]),
                      len(values[1]))

    for block in values[0]:
        ret += struct.pack(BLOCK_BASE_FMT,
                           block[0], block[2], len(block[1]))
        for chk in block[1]:
            ret += chk_to_bytes(chk)

    for obj in values[1]:
        ret += struct.pack(ROOT_OBJ_FMT,
                           obj[0],
                           obj[1])
    return ret