我有一个代表从网络读取的字节的Python字符串,我需要从该字符串连续读取几个字节。例如,我在一个字符串中有9个字节,我需要将4个字节作为整数读取,2个字节作为short类型读取,并读取3个自定义数据类型的字节。
在Python中是否有reader可以执行此类操作:
在Python中是否有reader可以执行此类操作:
reader = reader(my_string)
integer = int.from_bytes(reader.read(4), 'big')
short = int.from_bytes(reader.read(2), 'big')
custom = customType.Unpack(reader.read(3))
我想使用struct.unpack,但是我不知道如何处理非原始类型。
有什么想法吗?
谢谢。