WOscBundleParser Class Reference

#include <WOscBundle.h>

List of all members.

Classes

class  WOscBundleRaw

Public Member Functions

void ResetStateMachine ()
void Clone (char **buffer, unsigned int *bufferLen) const
void Parse (const char *data, unsigned int len)
WOscTimeTag GetTimeTag () const
unsigned int GetItemCount () const
bool GetNextItem (const char **buffer, unsigned int *length)

Detailed Description

Raw bundle parsing. Allows analysis of bundles directly from a binary stream. If a data packet has been received the buffer can be casted to this class and the resulting object can be analyzed, e.g.

WOscBundleRaw* bundle = reinterpret_cast<WOscBundleRaw*>(data);

Examples:

WOscClient.cpp.

Definition at line 72 of file WOscBundle.h.


Member Function Documentation

unsigned int WOscBundleParser::GetItemCount (  )  const [inline]

Return the number of items in the bundle.

Examples:
WOscClient.cpp.

Definition at line 162 of file WOscBundle.h.

00162 { return m_nItems; }

bool WOscBundleParser::GetNextItem ( const char **  buffer,
unsigned int *  length 
) [inline]

Get the next item in the bundle.

Parameters:
buffer Pointer which receives a pointer to the internal data of the next item.
length Pointer which receives the length of the next item in bytes.
Returns:
True if there was an item left, false if no items left.

Definition at line 171 of file WOscBundle.h.

00172     {
00173         unsigned int dataLen = m_bundleLen - WOSC_BUNDLE_HEADER_SIZE;
00174         if ( m_nextItem >= m_nItems || m_offset >= dataLen )
00175             return false;
00176 
00177         *length = WOscUtil::BufferTo<int32_t>(m_bundle->m_bundleData + m_offset);
00178         *buffer = m_bundle->m_bundleData + m_offset + sizeof(uint32_t);
00179         m_offset += *length + sizeof(uint32_t);
00180         m_nextItem++;
00181 
00182         return true;
00183     }

WOscTimeTag WOscBundleParser::GetTimeTag (  )  const [inline]

Get the time tag. Bundle must have been parsed successfully before.

Examples:
WOscClient.cpp.

Definition at line 155 of file WOscBundle.h.

References WOscTimeTag::GetImmediateTime().

00156     {
00157         if ( m_bundle == NULL )
00158             return WOscTimeTag::GetImmediateTime();
00159         return WOscTimeTag(reinterpret_cast<const char*>(&m_bundle->m_timeTag));
00160     }

void WOscBundleParser::Parse ( const char *  data,
unsigned int  len 
) [inline]

Check if bundle layout correct and extract information required to iterate through all bundle items.

Examples:
WOscClient.cpp.

Definition at line 125 of file WOscBundle.h.

References WOSC_BUNDLE_TAG.

00126     {
00127         // reset all members to zero (0)
00128         memset(this, 0, sizeof(WOscBundleParser));
00129 
00130         const WOscBundleRaw* bundle = reinterpret_cast<const WOscBundleRaw*>(data);
00131 
00132         unsigned int dataLen = len - WOSC_BUNDLE_HEADER_SIZE;
00133         if ( dataLen > len )    // if wrapped
00134             throw WOscException(ERR_TOO_SHORT, __FILE__, __LINE__);
00135         if ( dataLen == 0 )
00136             throw WOscException(ERR_EMPTY_BUNDLE, __FILE__, __LINE__);
00137         if ( strncmp(bundle->m_tag, WOSC_BUNDLE_TAG, sizeof(bundle->m_tag)) != 0 )
00138             throw WOscException(ERR_INVALID_TAG, __FILE__, __LINE__);
00139 
00140         // check if layout valid by stepping through bundle
00141         unsigned int offset = 0;
00142         for ( ; offset + sizeof(int32_t) < dataLen; m_nItems++ ) {
00143             int itemLen = WOscUtil::BufferTo<int32_t>(bundle->m_bundleData+offset);
00144             offset += itemLen + sizeof(uint32_t);
00145         }
00146         if ( offset != dataLen ) {
00147             throw WOscException(ERR_CURRUPT_BUNDLE_LAYOUT, __FILE__, __LINE__);
00148         }
00149         if ( m_nItems == 0 )
00150             throw WOscException(ERR_NO_ITEMS_IN_BUNDLE, __FILE__, __LINE__);
00151         m_bundle = bundle;
00152         m_bundleLen = len;
00153     }


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