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

Discussion in 'Python' started by Hans Müller, Mar 19, 2010.

  1. Hans Müller

    Hans Müller Guest

    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
     
    Hans Müller, Mar 19, 2010
    #1
    1. Advertising

  2. 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'
     
    Emile van Sebille, Mar 19, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tzury Bar Yochay
    Replies:
    4
    Views:
    582
    John Machin
    Sep 21, 2008
  2. palmeira

    write binary with struct.pack_into

    palmeira, Oct 6, 2012, in forum: Python
    Replies:
    3
    Views:
    327
    Alexander Blinne
    Oct 6, 2012
  3. Dennis Lee Bieber

    Re: write binary with struct.pack_into

    Dennis Lee Bieber, Oct 6, 2012, in forum: Python
    Replies:
    2
    Views:
    181
    Chris Angelico
    Oct 6, 2012
  4. Chris Angelico

    Re: write binary with struct.pack_into

    Chris Angelico, Oct 6, 2012, in forum: Python
    Replies:
    0
    Views:
    221
    Chris Angelico
    Oct 6, 2012
  5. Peter Otten

    Re: write binary with struct.pack_into

    Peter Otten, Oct 6, 2012, in forum: Python
    Replies:
    0
    Views:
    179
    Peter Otten
    Oct 6, 2012
Loading...

Share This Page