5 memset(queue, 0,
sizeof(*queue));
7 queue->_buffer = buffer;
11 bool twr_queue_put(twr_queue_t *queue,
const void *buffer,
size_t length)
18 if (
sizeof(length) + length > queue->_size - queue->_length)
23 uint8_t *p = queue->_buffer;
27 memcpy(p, &length,
sizeof(length));
31 queue->_length +=
sizeof(length) + length;
35 memcpy(p, buffer, length);
47 if (queue->_length == 0)
52 uint8_t *p = queue->_buffer;
54 memcpy(length, p,
sizeof(*length));
58 queue->_length -=
sizeof(*length) + *length;
62 memcpy(buffer, p, *length);
65 memmove(queue->_buffer, p + *length, queue->_length);
void twr_queue_init(twr_queue_t *queue, void *buffer, size_t size)
Initialize queue.
bool twr_queue_put(twr_queue_t *queue, const void *buffer, size_t length)
Put buffer to queue.
bool twr_queue_get(twr_queue_t *queue, void *buffer, size_t *length)
Get queue to buffer.
void twr_queue_clear(twr_queue_t *queue)
Clear queue.