This class is not intended for use by those using Pika in their applications. This documentation is for those who are extending Pika or otherwise working on the driver itself.


This is an implementation of a simple buffer. SimpleBuffer just handles a string of bytes. The clue, is that you can pop data from the beginning and append data to the end.

It’s ideal to use as a network buffer, from which you send data to the socket. Use this to avoid concatenating or splitting large strings.

class pika.simplebuffer.SimpleBuffer(data=None)[source]

A simple buffer that will handle storing, reading and sending strings to a socket.

>>> b = SimpleBuffer("abcdef")
>>> b.read_and_consume(3)
>>> b.write(None, '')
>>> repr(b)
"<SimpleBuffer of 3 bytes, 6 total size, 'def'>"
>>> str(b)
"<SimpleBuffer of 3 bytes, 6 total size, 'def'>"
>>> b.flush()

Append given strings to the buffer.

Parameters:data_strings (str|unicode) – Value to write to the buffer

Read the data from the buffer, at most ‘size’ bytes.

Parameters:size (int) – The number of bytes to read

Move pointer and discard first ‘size’ bytes.

Parameters:size (int) – The number of bytes to consume

Read up to ‘size’ bytes, also remove it from the buffer.

Parameters:size (int) – The number of bytes to read and consume
Return type:str

Faster way of sending buffer data to socket ‘sd’.

Parameters:sd (socket.socket) – The socket to send data to
Return type:int

Remove all the data from buffer.