python - I don't understand struct.unpack -
with next code:
shmem = mmap.mmap(0, 20, "mumblelink", mmap.access_read) print("size: "+str(struct.calcsize("il3f3f3f512s3f"))) print(struct.unpack("il3f3f3f512s3f", shmem))
i output:
size: 568 traceback (most recent call last): file "c:\users\saelyth\desktop\test.py", line 8, in <module> print(struct.unpack("il3f3f3f512s3f", shmem)) struct.error: unpack requires bytes object of length 568
why tells me requires object of length 568 if calcsize says it's 568?
also, worth mention had been googling (and checked this) answer of il3f3f3f512s3f or how can create own string read memory of example 1024, not 568, far had no luck. detailed answer on how part of struct works help, or point me in right direction of how understand how calculate string need use unpack shmem.
this related this question.
you check size in output, size not available memory map. change first line to:
shmem = mmap.mmap(0, 568, "mumblelink", mmap.access_read);
which matches size of struct. if want, can size first, create memory map match (second parameter.)
Comments
Post a Comment