diff --git a/utils/p4runtime_lib/convert.py b/utils/p4runtime_lib/convert.py index 2ac33c541..af9828583 100644 --- a/utils/p4runtime_lib/convert.py +++ b/utils/p4runtime_lib/convert.py @@ -102,6 +102,15 @@ def encode(x, bitwidth): assert(len(encoded_bytes) == byte_len) return encoded_bytes +def decode(enc_val): + decode_functions = [decodeIPv6, decodeIPv4, decodeMac, decodeNum] + for func in decode_functions: + try: + return func(enc_val) + except: + pass + raise Exception("Not compatible with the encoded value format") + if __name__ == '__main__': # TODO These tests should be moved out of main eventually mac = "aa:bb:cc:dd:ee:ff"