Generic buffer. More...
#include <lwmsg/buffer.h>
Data Fields | |
unsigned char * | base |
Pointer to base of memory block. | |
unsigned char * | end |
Pointer one byte past the end of the memory block. | |
unsigned char * | cursor |
Pointer to current position in the buffer. | |
LWMsgStatus(* | wrap )(struct LWMsgBuffer *buffer, size_t needed) |
Buffer wrap callback. More... | |
void * | data |
User data pointer. | |
This structure comprises a generic buffer used as as a source or destination for data streams when performing various operations such as marshalling, printing, etc. It contains pointers which delimit the start, end, and current position within a contiguous block of memory. It also contains an optional wrap callback function which is invoked when the cursor reaches the end of the buffer. This function may reset, refill, or resize the buffer so that the operation can continue.
LWMsgStatus(* LWMsgBuffer::wrap)(struct LWMsgBuffer *buffer, size_t needed) |
This optional callback is invoked when the end of the buffer is reached. It may arbitrarily modify the base, end, and cursor pointers, so long as the condition (end - cursor) >= 1 holds – that is, there must be at least one unused or unread byte in the buffer.
The needed parameter specifies the number of bytes the marshaller is immediately attempting to read or write, but it is merely a suggestion. In the interest of amortizing calls to this function, it is better to make the usable portion of the buffer (end - cursor) a large as possible on each call. It is safe to return with (end - cursor) < needed, but this is not recommended.
A needed value of 0 indicates that the operation in question (e.g. lwmsg_data_marshal()) is complete, and is an opportunity to perform any final cleanup (e.g. flushing the partially filled buffer to the underlying data stream).
[in,out] | buffer | the buffer structure |
[in] | needed | the number of bytes immediately needed, or 0 if finished |
LWMSG_STATUS_SUCCESS | success |
LWMSG_STATUS_MEMORY | out of memory |
... | implementation-specific error |
Likewise Message Library, part of the Likewise platform
Copyright © 2018 Likewise Software. All rights reserved.