simplebuffer

Note

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.

SimpleBuffer

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)
'abc'
>>> b.write(None, '')
>>> b.read(0)
''
>>> repr(b)
"<SimpleBuffer of 3 bytes, 6 total size, 'def'>"
>>> str(b)
"<SimpleBuffer of 3 bytes, 6 total size, 'def'>"
>>> b.flush()
>>> b.read(1)
''
SimpleBuffer.write(*data_strings)[source]

Append given strings to the buffer.

Parameters:data_strings (str or unicode) – Value to write to the buffer
SimpleBuffer.read(size=None)[source]

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

Parameters:size (int) – The number of bytes to read
SimpleBuffer.consume(size)[source]

Move pointer and discard first ‘size’ bytes.

Parameters:size (int) – The number of bytes to consume
SimpleBuffer.read_and_consume(size)[source]

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
SimpleBuffer.send_to_socket(sd)[source]

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

Parameters:sd (socket.socket) – The socket to send data to
Return type:int
SimpleBuffer.flush()[source]

Remove all the data from buffer.

Project Versions

Table Of Contents

Previous topic

heartbeat

Next topic

spec

This Page