Example #1
0
def decode_single(typ, data):
    if is_hex_encoded_value(data):
        warnings.warn(
            DeprecationWarning(
                "Automatic inference of hex encoded data has been deprecated. "
                "Please adjust your code to ensure that the data argument for "
                "`decode_single` is a byte string"))
        data = decode_hex(remove_0x_prefix(data))

    if is_text(data):
        warnings.warn(
            DeprecationWarning(
                "Automatic conversion of encoded data to bytes has been deprecated. "
                "Please adjust your code to ensure that the data argument for "
                "`decode_single` is a byte string"))
        data = force_bytes(data)

    try:
        base, sub, arrlist = typ
    except ValueError:
        base, sub, arrlist = process_type(typ)

    decoder = get_single_decoder(base, sub, arrlist)
    stream = BytesIO(data)
    return decoder(stream)
Example #2
0
def test_multi_decoder(types, data, expected):
    decoders = tuple((
        get_single_decoder(*process_type(t)) for t in types
    ))
    decoder = MultiDecoder.as_decoder(decoders=decoders)
    stream = BytesIO(decode_hex(data))
    actual = decoder(stream)
    assert actual == expected
Example #3
0
def decode_single(typ, data):
    if not is_bytes(data):
        raise TypeError(
            "The `data` value must be of bytes type.  Got {0}".format(
                type(data)))
    try:
        base, sub, arrlist = typ
    except ValueError:
        base, sub, arrlist = process_type(typ)

    decoder = get_single_decoder(base, sub, arrlist)
    stream = BytesIO(data)
    return decoder(stream)