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))
评论列表
文章目录