WOscBlob Class Reference

#include <WOscBlob.h>

List of all members.

Public Types

enum  Constants { BLOB_SIZE_SIZE = 4 }

Public Member Functions

 WOscBlob (const char *binaryData)
 WOscBlob (const char *binaryData, int dataLen)
 WOscBlob (WOscBlob *b)
 WOscBlob (WOscBlob &b)
virtual ~WOscBlob ()
WOscBloboperator= (WOscBlob &rhs)
int GetDataLen () const
const char * GetData () const
int GetBufferLen () const
void GetBuffer (char *buffer, int bufferLen) const
const char * GetBuffer () const

Detailed Description

Encapsulates an OSC-blob for transmission of binary data. Used to transport proprietary data over the OSC-protocol. Inherit your own class from this object, for instance a firmware-packet class, which could transport binary data fo firmware updates.

Remarks:
When using datagram transmission, make sure that the receive-buffer of the other peer can handle your OSC-packet size (most systems can handle UDP datagram-packets of sizes up to 512bytes)
Todo:
Change GetBufferLen to getDataLenZeroPadded

Definition at line 61 of file WOscBlob.h.


Member Enumeration Documentation

Enumerator:
BLOB_SIZE_SIZE 

Size of blob's size.

Definition at line 78 of file WOscBlob.h.

00078                   {
00079         BLOB_SIZE_SIZE = 4,     /**< Size of blob's size. */
00080     };


Constructor & Destructor Documentation

WOscBlob::WOscBlob ( const char *  binaryData  ) 

Constructor for WOscBlobs from a binary buffer containing an WOscBlob in its binary representation ( [blobsize][blobdata] ).

Parameters:
binaryData Pointer to the buffer containing the raw data.
Remarks:
Does not handle illegal blob sizes when passing wrong buffers.

Definition at line 56 of file WOscBlob.cpp.

References BLOB_SIZE_SIZE, WOscUtil::GetSizeFourByteAligned(), and WOscBlob().

Referenced by WOscBlob().

00057 {
00058     // get blob size
00059     m_dataLen = WOscUtil::BufferTo<int>(binaryData);
00060     m_bufferLen = WOscUtil::GetSizeFourByteAligned( m_dataLen ) + BLOB_SIZE_SIZE;
00061     m_buffer = new char[m_bufferLen] ;
00062 
00063     // write data to buffer 
00064     memcpy(m_buffer, binaryData, m_bufferLen);
00065 }

WOscBlob::WOscBlob ( const char *  binaryData,
int  dataLen 
)

Constructs a WOscBlob-object from a binary buffer. The buffer is internally rounded up to a multiple of 4. If querying fo buffer size, the padded size is returned. To get the actual data length, use the GetDataLen() function.

Parameters:
binaryData Buffer with data of length "dataLen".
dataLen Length of data supplied with "binaryData".
Exceptions:
None. 
Remarks:
Check general information at WOscBlob .
 
 +-------------------+----//---------------------+
 | size of blob data | blob data + padding zeros |
 +-------------------+---------------------------+

 |----- 4 bytes -----|-- size rounded up bytes --|

   

Definition at line 107 of file WOscBlob.cpp.

References BLOB_SIZE_SIZE, WOscUtil::GetSizeFourByteAligned(), and WOscBlob().

00108 {
00109     m_dataLen = dataLen;
00110 
00111     /* round up and allocate */
00112     m_bufferLen = WOscUtil::GetSizeFourByteAligned(dataLen) + BLOB_SIZE_SIZE;
00113     m_buffer = new char[m_bufferLen];
00114     
00115     /* write size to buffer */
00116     WOscUtil::FillBufferWith(m_buffer, dataLen);
00117     
00118     /* write data to buffer */
00119     memcpy(m_buffer + BLOB_SIZE_SIZE, binaryData, m_dataLen);
00120 
00121     /* zeropad buffer */
00122     for ( int i = m_dataLen + BLOB_SIZE_SIZE; i < m_bufferLen; i++ )
00123         m_buffer[i] = 0;
00124 }

WOscBlob::WOscBlob ( WOscBlob b  ) 

Pointer-copy-constructor. Copies the content of the referenced blob into this one.

Parameters:
b Reference to another blob.
Exceptions:
None. 
Remarks:
None.

Definition at line 160 of file WOscBlob.cpp.

References WOscBlob().

00161 {
00162     m_buffer = NULL;
00163     *this = *b;
00164 }

WOscBlob::WOscBlob ( WOscBlob b  ) 

Copy-constructor. Copies the content of the referenced blob into this one.

Parameters:
b Reference to another blob.
Exceptions:
None. 
Remarks:
None.

Definition at line 177 of file WOscBlob.cpp.

References WOscBlob().

00178 {
00179     m_buffer = NULL;
00180     *this = b;
00181 }

WOscBlob::~WOscBlob (  )  [virtual]

Deletes the WOscBlob-object. The internal buffer gets deleted.

Exceptions:
None. 
Remarks:
None.

Definition at line 191 of file WOscBlob.cpp.

00192 {
00193     delete [] m_buffer;
00194 }


Member Function Documentation

const char * WOscBlob::GetBuffer (  )  const

Returns a pointer to an internal buffer containing the current binary representation of this blob. Please see remarks for safety issues.

Returns:
Pointer to internal array data.
Exceptions:
None. 
Remarks:
The pointer remains valid until the modification of this blob-object. The next time the blob is destination of an operation (check operators) or the blob will be deleted this pointer gets invalid. If you are not sure about that issue, please use the other getBuffer()- function.
See also:
WOscBlob::getBuffer(char* buffer, int bufferLen)

Definition at line 271 of file WOscBlob.cpp.

00272 {
00273     return m_buffer;
00274 }

void WOscBlob::GetBuffer ( char *  buffer,
int  bufferLen 
) const

Fills the buffer with the raw bytestream of this blob. The user must supply the buffer of apropriate size.

Parameters:
buffer Caller supplied destination buffer.
bufferLen Length of the supplied buffer.
Exceptions:
WOscException When caller supplied buffer too small.
Remarks:
This interface makes sure that the buffer remains valid when modifying the blob-object afterwards. (contrary to WOscBlob::getBuffer() )
See also:
WOscBlob::getBuffer()

Definition at line 246 of file WOscBlob.cpp.

References ERR_BUFFER_TO_SMALL.

00247 {
00248     if ( bufferLen < m_bufferLen )
00249         throw WOscException(ERR_BUFFER_TO_SMALL, __FILE__, __LINE__);
00250     memcpy(buffer, m_buffer, m_bufferLen);
00251 }

int WOscBlob::GetBufferLen (  )  const

Returns the buffer-length of the formatted buffer. This length includes zero-padding and size of the blob size.

Returns:
Size of the formatted buffer.
See also:
GetDataLen()

Definition at line 220 of file WOscBlob.cpp.

Referenced by WOscMessage::WOscMessage().

00221 {
00222     return m_bufferLen;
00223 }

const char * WOscBlob::GetData (  )  const

Returns a pointer to the blob data. Get the length of the buffer with WOscBlob::GetDataLength() .

Returns:
Pointer to the buffer containing the data.

Definition at line 73 of file WOscBlob.cpp.

References BLOB_SIZE_SIZE.

00074 {
00075     return m_buffer + BLOB_SIZE_SIZE;
00076 }

int WOscBlob::GetDataLen (  )  const

Returns the length of the data without zero-padding.

Returns:
Size without zeros.
See also:
GetBufferLen()

Definition at line 205 of file WOscBlob.cpp.

00206 {
00207     return m_dataLen;
00208 }

WOscBlob & WOscBlob::operator= ( WOscBlob rhs  ) 

Assignment operator. Copies the content of the referenced blob into this one.

Parameters:
rhs Reference to another blob (right hand side of operator).
Exceptions:
None. 
Remarks:
None.

Definition at line 137 of file WOscBlob.cpp.

00138 {
00139     if ( this != &rhs ) {
00140         delete [] m_buffer;
00141         m_dataLen = rhs.m_dataLen;
00142         m_bufferLen = rhs.m_bufferLen;
00143         m_buffer = new char[m_bufferLen];
00144         memcpy(m_buffer, rhs.m_buffer, m_bufferLen);
00145     }
00146     return *this;
00147 }


The documentation for this class was generated from the following files:
Generated on Sat Oct 23 03:05:59 2010 for WOscLib by  doxygen 1.6.3