[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Reserving binary Buffer for struct.pack_into() of exact length

Hans Müller

3/19/2010 6:47:00 PM

Hello,

I need some buffers, which are beeing concatenated an then send via
the socket() function.
My problem is that create_string_buffer() creates a buffer which ist
one byte too long (for a \0 char). But when I concatenate some of
these buffers to a long one to be transfered, the extra byte is
corrupting the resulting buffer.
Of course I could slice the buffer before being concatended, but
this looks ugly to me.
Is there a way to create a writeable buffer object without the \0 byte ?

Thanks a lot

Hans
1 Answer

Emile van Sebille

3/19/2010 8:33:00 PM

0

On 3/19/2010 11:46 AM Hans Müller said...
> Hello,
>
> I need some buffers, which are beeing concatenated an then send via the
> socket() function.
> My problem is that create_string_buffer() creates a buffer which ist one
> byte too long (for a \0 char). But when I concatenate some of these
> buffers to a long one to be transfered, the extra byte is corrupting the
> resulting buffer.
> Of course I could slice the buffer before being concatended, but
> this looks ugly to me.
> Is there a way to create a writeable buffer object without the \0 byte ?
>
> Thanks a lot
>
> Hans

>>> p = create_string_buffer(5)
>>> p.raw='hello'
>>> p.value
'hello'