TekPattern.py 文件源码

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

项目:QGL 作者: BBN-Q 项目源码 文件源码
def write_field(FID, fieldName, data, dataType):
    typeSizes = {'int16': 2, 'int32': 4, 'double': 8, 'uint128': 16}
    formatChars = {'int16': '<h', 'int32': '<i', 'double': '<d'}

    if dataType == 'char':
        dataSize = len(data) + 1
        data = data + chr(0)
    else:
        dataSize = typeSizes[dataType]

    FID.write(struct.pack('<II', len(fieldName) + 1, dataSize))
    FID.write(fieldName + chr(0))
    if dataType == 'char':
        FID.write(data)
    elif dataType == 'uint128':
        #struct doesn't support uint128 so write two 64bits
        #there are smarter ways but we really only need this for the fake timestamp
        FID.write(struct.pack('<QQ', 0, data))
    else:
        FID.write(struct.pack(formatChars[dataType], data))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号