bmv2stf.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:p4app 作者: p4lang 项目源码 文件源码
def makeMask(self, value):
        # TODO -- we really need to know the size of the key to make the mask properly,
        # but to find that, we need to parse the headers and header_types from the json
        if value.startswith("0x"):
            mask = "F"
            value = value[2:]
            prefix = "0x"
        elif value.startswith("0b"):
            mask = "1"
            value = value[2:]
            prefix = "0b"
        elif value.startswith("0o"):
            mask = "7"
            value = value[2:]
            prefix = "0o"
        else:
            raise Exception("Decimal value "+value+" not supported for ternary key")
            return value
        values = "0123456789abcdefABCDEF*"
        replacements = (mask * 22) + "0"
        trans = maketrans(values, replacements)
        m = value.translate(trans)
        return prefix + value.replace("*", "0") + "&&&" + prefix + m
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号