Skip to content
Lucio Santi edited this page Aug 1, 2014 · 2 revisions

PTC WikiCode overviewbuffer

This module implements a byte buffer (DataBuffer) which is used by the control block as both incoming and outgoing data buffers. Since data might arrive out of order, this buffer includes some methods that honor this fact. As an example, the method add_chunk takes as arguments an offset inside the buffer and the byte chunk to be added after that offset. The following code snippet shows how this method can be used:

>>> buffer = DataBuffer()
>>> buffer.add_chunk(8, 'baz')
>>> buffer.add_chunk(4, 'bar ')
>>> buffer.put('foo ')
>>> buffer.get(15)
'foo bar baz'
>>> buffer.empty()
True

Note that get removes the data from the buffer. The argument received represents the maximum number of bytes to be extracted, although the actual number might be even less.

Clone this wiki locally