DasBuf Struct Reference

#include <das2/buffer.h>


Detailed Description

Little buffer class to handle accumulating string data.

DasBuf objects maintain a data buffer with a current write point, a current read point and an end read point. As data are written to the buffer the write point is incremented as well as the end-of-read point. This structure is handy when multiple functions need to contribute encoded data to a single memory buffer, or when multiple functions need to read from a buffer with out memory re-allocations or placing null values to stop parsing.

It is hoped that the use of this class cuts down on alot of data copies and sub-string allocations.

Public Member Functions

DasBufnew_DasBuf (size_t uLen)
 Create a new Read-Write buffer on the heap Allocates a new char buffer of the indicated size, call del_DasBuffer() when finished.
ErrorCode DasBuf_initReadWrite (DasBuf *pThis, char *sBuf, size_t uLen)
 Initialize a read-write buffer that points to an external byte array.
void DasBuf_reinit (DasBuf *pThis)
 Re-initialize a buffer including read and write points This version can be a little quicker than init_DasBuffer() because it only zero's out the bytes that were written, not the entire buffer.
void del_DasBuf (DasBuf *pThis)
 Free a buffer object along with it's backing store.
ErrorCode DasBuf_printf (DasBuf *pThis, const char *sFmt,...)
 Add string data to the buffer.
ErrorCode DasBuf_write (DasBuf *pThis, const void *pData, size_t uLen)
 Add generic data to the buffer.
size_t DasBuf_written (const DasBuf *pThis)
 Get the size of the data in the buffer.
size_t DasBuf_unread (const DasBuf *pThis)
 Get the number of bytes remaining from the read begin point to the read end point.
size_t DasBuf_strip (DasBuf *pThis)
 Adjust read points so that the data starts and ends on non-space values.
size_t DasBuf_read (DasBuf *pThis, char *pOut, size_t uOut)
 Read bytes from a buffer Copies bytes into a buffer and increments the read point.

Member Function Documentation

DasBuf * new_DasBuf ( size_t  uLen  ) 

Create a new Read-Write buffer on the heap Allocates a new char buffer of the indicated size, call del_DasBuffer() when finished.

Parameters:
uLen The length of the raw buffer to allocate
Returns:
a new DasBuf allocated on the heap.
ErrorCode DasBuf_initReadWrite ( DasBuf pThis,
char *  sBuf,
size_t  uLen 
)

Initialize a read-write buffer that points to an external byte array.

The write point is reset to the beginning and funtion zero's all data. The read point is also set to the beginning.

Parameters:
pThis the buffer initialize
sBuf an pre-allocated character buffer to receive new data
uLen the length of the pre-allocated buffer
void del_DasBuf ( DasBuf pThis  ) 

Free a buffer object along with it's backing store.

Don't use this if the DasBuffer::sBuf member points to data on the stack if so, your program will crash.

Parameters:
pBuf The buffer to free
ErrorCode DasBuf_printf ( DasBuf pThis,
const char *  sFmt,
  ... 
)

Add string data to the buffer.

Parameters:
pThis the buffer to receive the bytes
sFmt an sprintf style format string
Returns:
0 if the operation succeeded, a positive error code otherwise.
ErrorCode DasBuf_write ( DasBuf pThis,
const void *  pData,
size_t  uLen 
)

Add generic data to the buffer.

Parameters:
pThis the buffer to receive the bytes
pData a pointer to the bytes to write
nLen the number of bytes to write
Returns:
0 if the operation succeeded, a positive error code otherwise.
size_t DasBuf_written ( const DasBuf pThis  ) 

Get the size of the data in the buffer.

Returns:
the number of bytes written to the buffer
size_t DasBuf_unread ( const DasBuf pThis  ) 

Get the number of bytes remaining from the read begin point to the read end point.

Normally this returns the difference between the read point and the write point but some operations such as DasBuf_strip() reduce the read end point below the write point.

Returns:
Read length remaining.
size_t DasBuf_strip ( DasBuf pThis  ) 

Adjust read points so that the data starts and ends on non-space values.

This is handy if the buffer contains string data.

Warning:
If any new bytes are added after the buffer has been stripped then the right read point will be reset to the end of valid data.
Returns:
The number of bytes left to read after moving the read boundaries. The return value is the same as what you would get by calling DasBuf_remaining() immediately after this function.
size_t DasBuf_read ( DasBuf pThis,
char *  pOut,
size_t  uOut 
)

Read bytes from a buffer Copies bytes into a buffer and increments the read point.

As soon as the read point hits the end of valid data no more bytes are copied.

Returns:
The number of bytes copied out of the buffer.

The documentation for this struct was generated from the following file:
 All Data Structures Files Functions Variables Typedefs Enumerations Defines

Generated on 11 Sep 2016 for Das2 Stream Utilities by  doxygen 1.6.1