En Sat, 20 Sep 2008 15:45:48 -0300, Tzury Bar Yochay
<Af**********@gmail.comescribió:
I can't find in the documentation the way to use these two functions.
can someone share a simple code that utilize these two functions?
struct.pack_into is intended to "fill" a buffer you got from somewhere,
probably other language or process. ctypes.create_string_buffer may be
used to create a writable buffer in python code.
pyfrom ctypes import create_string_buffer
pyb = create_string_buffer(10)
pyb.raw
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
pyfrom struct import *
pypack_into("hhh", b, 0, 1, 2, -1)
pyb.raw
'\x01\x00\x02\x00\xff\xff\x00\x00\x00\x00'
unpack_from does the opposite.
Before Python 2.5, you had to use pack to create a string object, and then
copy its contents into the destination buffer; using pack_into avoids the
memory copy.
--
Gabriel Genellina