45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
'''
|
|
* @Author : zoufuzhou
|
|
* @Date : 2024-09-02 16:34:37
|
|
* @Description : Fixed element pointer position.
|
|
The current pointer points to the latest element
|
|
* @LastEditTime : 2024-09-05 16:34:37
|
|
'''
|
|
from log.LogUtil import LogUtil
|
|
import struct
|
|
from shm.MemTable import MemTable
|
|
from shm.Serialization import Serialization
|
|
import logging as d
|
|
|
|
|
|
# 测试代码
|
|
if __name__ == '__main__':
|
|
LogUtil.init("app")
|
|
d.debug("test")
|
|
mm = MemTable('TRKSET', 80,100) # 初始化
|
|
# mm.clear() # 清空内存
|
|
# for i in range(51):
|
|
#
|
|
# # 打包数据
|
|
# packed_data = b'' # 初始化空字节串
|
|
#
|
|
# for data in range(1, 26):
|
|
# # 使用 struct.pack() 打包每个数据项
|
|
# packed_data += struct.pack('h', data)
|
|
# mm.push(packed_data) # 写入数据
|
|
#
|
|
# packed_data = mm.getCur()
|
|
# d.debug(f"packed_data: {struct.unpack('25h', packed_data)}")
|
|
|
|
data_tuple = ('hello','hello','hi',1,2,3,4)
|
|
serializ = Serialization('21s21s21siifi')
|
|
mm.push(serializ.serialize(data_tuple))
|
|
for i in range(mm.count()):
|
|
packed_data = mm.read(i)
|
|
#d.debug(f"packed_data: { packed_data}")
|
|
#entid,extid,stell,length,width,thick,weight = struct.unpack('21s21s21siifi', packed_data)
|
|
#d.debug(f"packed_data: { entid.decode('utf-8')},{extid.decode('utf-8')},{stell.decode('utf-8')},{length},{width},{thick},{weight}")
|
|
result = serializ.deserialize(packed_data)
|
|
d.debug(f"result:{result}")
|