Exemplo n.º 1
0
def encode_high(data, columns, security_level):
    """Converts the input string to high level code words.

    Including the length indicator and the error correction words, but without
    padding.
    """

    # Encode data to code words
    data_words = list(compact(data))
    data_count = len(data_words)

    # Get the padding to align data to column count
    ec_count = 2**(security_level + 1)
    padding_words = get_padding(data_count, ec_count, columns)
    padding_count = len(padding_words)

    # Check the generated bar code's size is within specification parameters
    validate_barcode_size(data_count, ec_count, padding_count, columns)

    # Length includes the data CWs, padding CWs and the specifier itself
    length = data_count + padding_count + 1

    # Join encoded data with the length specifier and padding
    extendend_words = [length] + data_words + padding_words

    # Calculate error correction words
    ec_words = compute_error_correction_code_words(extendend_words,
                                                   security_level)

    return extendend_words + ec_words
Exemplo n.º 2
0
 def do_compact(str):
     return list(compact(to_bytes(str)))