You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

807 lines
21KB

  1. /*
  2. oscpack -- Open Sound Control (OSC) packet manipulation library
  3. http://www.rossbencina.com/code/oscpack
  4. Copyright (c) 2004-2013 Ross Bencina <rossb@audiomulch.com>
  5. Permission is hereby granted, free of charge, to any person obtaining
  6. a copy of this software and associated documentation files
  7. (the "Software"), to deal in the Software without restriction,
  8. including without limitation the rights to use, copy, modify, merge,
  9. publish, distribute, sublicense, and/or sell copies of the Software,
  10. and to permit persons to whom the Software is furnished to do so,
  11. subject to the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  18. ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. /*
  23. The text above constitutes the entire oscpack license; however,
  24. the oscpack developer(s) also make the following non-binding requests:
  25. Any person wishing to distribute modifications to the Software is
  26. requested to send the modifications to the original developer so that
  27. they can be incorporated into the canonical version. It is also
  28. requested that these non-binding requests be included whenever the
  29. above license is reproduced.
  30. */
  31. #include "OscReceivedElements.h"
  32. #include "OscHostEndianness.h"
  33. #include <cstddef> // ptrdiff_t
  34. namespace osc{
  35. // return the first 4 byte boundary after the end of a str4
  36. // be careful about calling this version if you don't know whether
  37. // the string is terminated correctly.
  38. static inline const char* FindStr4End( const char *p )
  39. {
  40. if( p[0] == '\0' ) // special case for SuperCollider integer address pattern
  41. return p + 4;
  42. p += 3;
  43. while( *p )
  44. p += 4;
  45. return p + 1;
  46. }
  47. // return the first 4 byte boundary after the end of a str4
  48. // returns 0 if p == end or if the string is unterminated
  49. static inline const char* FindStr4End( const char *p, const char *end )
  50. {
  51. if( p >= end )
  52. return 0;
  53. if( p[0] == '\0' ) // special case for SuperCollider integer address pattern
  54. return p + 4;
  55. p += 3;
  56. end -= 1;
  57. while( p < end && *p )
  58. p += 4;
  59. if( *p )
  60. return 0;
  61. else
  62. return p + 1;
  63. }
  64. // round up to the next highest multiple of 4. unless x is already a multiple of 4
  65. static inline uint32 RoundUp4( uint32 x )
  66. {
  67. return (x + 3) & ~((uint32)0x03);
  68. }
  69. static inline int32 ToInt32( const char *p )
  70. {
  71. #ifdef OSC_HOST_LITTLE_ENDIAN
  72. union{
  73. osc::int32 i;
  74. char c[4];
  75. } u;
  76. u.c[0] = p[3];
  77. u.c[1] = p[2];
  78. u.c[2] = p[1];
  79. u.c[3] = p[0];
  80. return u.i;
  81. #else
  82. return *(int32*)p;
  83. #endif
  84. }
  85. static inline uint32 ToUInt32( const char *p )
  86. {
  87. #ifdef OSC_HOST_LITTLE_ENDIAN
  88. union{
  89. osc::uint32 i;
  90. char c[4];
  91. } u;
  92. u.c[0] = p[3];
  93. u.c[1] = p[2];
  94. u.c[2] = p[1];
  95. u.c[3] = p[0];
  96. return u.i;
  97. #else
  98. return *(uint32*)p;
  99. #endif
  100. }
  101. static inline int64 ToInt64( const char *p )
  102. {
  103. #ifdef OSC_HOST_LITTLE_ENDIAN
  104. union{
  105. osc::int64 i;
  106. char c[8];
  107. } u;
  108. u.c[0] = p[7];
  109. u.c[1] = p[6];
  110. u.c[2] = p[5];
  111. u.c[3] = p[4];
  112. u.c[4] = p[3];
  113. u.c[5] = p[2];
  114. u.c[6] = p[1];
  115. u.c[7] = p[0];
  116. return u.i;
  117. #else
  118. return *(int64*)p;
  119. #endif
  120. }
  121. static inline uint64 ToUInt64( const char *p )
  122. {
  123. #ifdef OSC_HOST_LITTLE_ENDIAN
  124. union{
  125. osc::uint64 i;
  126. char c[8];
  127. } u;
  128. u.c[0] = p[7];
  129. u.c[1] = p[6];
  130. u.c[2] = p[5];
  131. u.c[3] = p[4];
  132. u.c[4] = p[3];
  133. u.c[5] = p[2];
  134. u.c[6] = p[1];
  135. u.c[7] = p[0];
  136. return u.i;
  137. #else
  138. return *(uint64*)p;
  139. #endif
  140. }
  141. //------------------------------------------------------------------------------
  142. bool ReceivedPacket::IsBundle() const
  143. {
  144. return (Size() > 0 && Contents()[0] == '#');
  145. }
  146. //------------------------------------------------------------------------------
  147. bool ReceivedBundleElement::IsBundle() const
  148. {
  149. return (Size() > 0 && Contents()[0] == '#');
  150. }
  151. osc_bundle_element_size_t ReceivedBundleElement::Size() const
  152. {
  153. return ToInt32( sizePtr_ );
  154. }
  155. //------------------------------------------------------------------------------
  156. bool ReceivedMessageArgument::AsBool() const
  157. {
  158. if( !typeTagPtr_ )
  159. throw MissingArgumentException();
  160. else if( *typeTagPtr_ == TRUE_TYPE_TAG )
  161. return true;
  162. else if( *typeTagPtr_ == FALSE_TYPE_TAG )
  163. return false;
  164. else
  165. throw WrongArgumentTypeException();
  166. }
  167. bool ReceivedMessageArgument::AsBoolUnchecked() const
  168. {
  169. if( !typeTagPtr_ )
  170. throw MissingArgumentException();
  171. else if( *typeTagPtr_ == TRUE_TYPE_TAG )
  172. return true;
  173. else if (*typeTagPtr_ == osc::TypeTagValues::FLOAT_TYPE_TAG) // Do conversion for touchOSC's limited values
  174. return AsFloatUnchecked() > 0;
  175. else
  176. return false;
  177. }
  178. int32 ReceivedMessageArgument::AsInt32() const
  179. {
  180. if (!typeTagPtr_)
  181. throw MissingArgumentException();
  182. else if (*typeTagPtr_ == INT32_TYPE_TAG)
  183. return AsInt32Unchecked();
  184. else if (*typeTagPtr_ == osc::TypeTagValues::FLOAT_TYPE_TAG) // Do conversion for touchOSC's limited values
  185. return static_cast<osc::int32>(AsFloatUnchecked());
  186. else
  187. throw WrongArgumentTypeException();
  188. }
  189. int32 ReceivedMessageArgument::AsInt32Unchecked() const
  190. {
  191. #ifdef OSC_HOST_LITTLE_ENDIAN
  192. union{
  193. osc::int32 i;
  194. char c[4];
  195. } u;
  196. u.c[0] = argumentPtr_[3];
  197. u.c[1] = argumentPtr_[2];
  198. u.c[2] = argumentPtr_[1];
  199. u.c[3] = argumentPtr_[0];
  200. return u.i;
  201. #else
  202. return *(int32*)argument_;
  203. #endif
  204. }
  205. float ReceivedMessageArgument::AsFloat() const
  206. {
  207. if (!typeTagPtr_)
  208. throw MissingArgumentException();
  209. else if (*typeTagPtr_ == FLOAT_TYPE_TAG)
  210. return AsFloatUnchecked();
  211. else if (*typeTagPtr_ == TRUE_TYPE_TAG) // Allow conversion to other types
  212. return 1.0f;
  213. else if (*typeTagPtr_ == FALSE_TYPE_TAG)
  214. return 0.0f;
  215. else if (*typeTagPtr_ == INT32_TYPE_TAG)
  216. return static_cast<float>(AsInt32Unchecked());
  217. else
  218. throw WrongArgumentTypeException();
  219. }
  220. float ReceivedMessageArgument::AsFloatUnchecked() const
  221. {
  222. #ifdef OSC_HOST_LITTLE_ENDIAN
  223. union{
  224. float f;
  225. char c[4];
  226. } u;
  227. u.c[0] = argumentPtr_[3];
  228. u.c[1] = argumentPtr_[2];
  229. u.c[2] = argumentPtr_[1];
  230. u.c[3] = argumentPtr_[0];
  231. return u.f;
  232. #else
  233. return *(float*)argument_;
  234. #endif
  235. }
  236. char ReceivedMessageArgument::AsChar() const
  237. {
  238. if( !typeTagPtr_ )
  239. throw MissingArgumentException();
  240. else if( *typeTagPtr_ == CHAR_TYPE_TAG )
  241. return AsCharUnchecked();
  242. else
  243. throw WrongArgumentTypeException();
  244. }
  245. char ReceivedMessageArgument::AsCharUnchecked() const
  246. {
  247. return (char)ToInt32( argumentPtr_ );
  248. }
  249. uint32 ReceivedMessageArgument::AsRgbaColor() const
  250. {
  251. if( !typeTagPtr_ )
  252. throw MissingArgumentException();
  253. else if( *typeTagPtr_ == RGBA_COLOR_TYPE_TAG )
  254. return AsRgbaColorUnchecked();
  255. else
  256. throw WrongArgumentTypeException();
  257. }
  258. uint32 ReceivedMessageArgument::AsRgbaColorUnchecked() const
  259. {
  260. return ToUInt32( argumentPtr_ );
  261. }
  262. uint32 ReceivedMessageArgument::AsMidiMessage() const
  263. {
  264. if( !typeTagPtr_ )
  265. throw MissingArgumentException();
  266. else if( *typeTagPtr_ == MIDI_MESSAGE_TYPE_TAG )
  267. return AsMidiMessageUnchecked();
  268. else
  269. throw WrongArgumentTypeException();
  270. }
  271. uint32 ReceivedMessageArgument::AsMidiMessageUnchecked() const
  272. {
  273. return ToUInt32( argumentPtr_ );
  274. }
  275. int64 ReceivedMessageArgument::AsInt64() const
  276. {
  277. if( !typeTagPtr_ )
  278. throw MissingArgumentException();
  279. else if( *typeTagPtr_ == INT64_TYPE_TAG )
  280. return AsInt64Unchecked();
  281. else
  282. throw WrongArgumentTypeException();
  283. }
  284. int64 ReceivedMessageArgument::AsInt64Unchecked() const
  285. {
  286. return ToInt64( argumentPtr_ );
  287. }
  288. uint64 ReceivedMessageArgument::AsTimeTag() const
  289. {
  290. if( !typeTagPtr_ )
  291. throw MissingArgumentException();
  292. else if( *typeTagPtr_ == TIME_TAG_TYPE_TAG )
  293. return AsTimeTagUnchecked();
  294. else
  295. throw WrongArgumentTypeException();
  296. }
  297. uint64 ReceivedMessageArgument::AsTimeTagUnchecked() const
  298. {
  299. return ToUInt64( argumentPtr_ );
  300. }
  301. double ReceivedMessageArgument::AsDouble() const
  302. {
  303. if( !typeTagPtr_ )
  304. throw MissingArgumentException();
  305. else if( *typeTagPtr_ == DOUBLE_TYPE_TAG )
  306. return AsDoubleUnchecked();
  307. else
  308. throw WrongArgumentTypeException();
  309. }
  310. double ReceivedMessageArgument::AsDoubleUnchecked() const
  311. {
  312. #ifdef OSC_HOST_LITTLE_ENDIAN
  313. union{
  314. double d;
  315. char c[8];
  316. } u;
  317. u.c[0] = argumentPtr_[7];
  318. u.c[1] = argumentPtr_[6];
  319. u.c[2] = argumentPtr_[5];
  320. u.c[3] = argumentPtr_[4];
  321. u.c[4] = argumentPtr_[3];
  322. u.c[5] = argumentPtr_[2];
  323. u.c[6] = argumentPtr_[1];
  324. u.c[7] = argumentPtr_[0];
  325. return u.d;
  326. #else
  327. return *(double*)argument_;
  328. #endif
  329. }
  330. const char* ReceivedMessageArgument::AsString() const
  331. {
  332. if( !typeTagPtr_ )
  333. throw MissingArgumentException();
  334. else if( *typeTagPtr_ == STRING_TYPE_TAG )
  335. return argumentPtr_;
  336. else
  337. throw WrongArgumentTypeException();
  338. }
  339. const char* ReceivedMessageArgument::AsSymbol() const
  340. {
  341. if( !typeTagPtr_ )
  342. throw MissingArgumentException();
  343. else if( *typeTagPtr_ == SYMBOL_TYPE_TAG )
  344. return argumentPtr_;
  345. else
  346. throw WrongArgumentTypeException();
  347. }
  348. void ReceivedMessageArgument::AsBlob( const void*& data, osc_bundle_element_size_t& size ) const
  349. {
  350. if( !typeTagPtr_ )
  351. throw MissingArgumentException();
  352. else if( *typeTagPtr_ == BLOB_TYPE_TAG )
  353. AsBlobUnchecked( data, size );
  354. else
  355. throw WrongArgumentTypeException();
  356. }
  357. void ReceivedMessageArgument::AsBlobUnchecked( const void*& data, osc_bundle_element_size_t& size ) const
  358. {
  359. // read blob size as an unsigned int then validate
  360. osc_bundle_element_size_t sizeResult = (osc_bundle_element_size_t)ToUInt32( argumentPtr_ );
  361. if( !IsValidElementSizeValue(sizeResult) )
  362. throw MalformedMessageException("invalid blob size");
  363. size = sizeResult;
  364. data = (void*)(argumentPtr_+ osc::OSC_SIZEOF_INT32);
  365. }
  366. std::size_t ReceivedMessageArgument::ComputeArrayItemCount() const
  367. {
  368. // it is only valid to call ComputeArrayItemCount when the argument is the array start marker
  369. if( !IsArrayBegin() )
  370. throw WrongArgumentTypeException();
  371. std::size_t result = 0;
  372. unsigned int level = 0;
  373. const char *typeTag = typeTagPtr_ + 1;
  374. // iterate through all type tags. note that ReceivedMessage::Init
  375. // has already checked that the message is well formed.
  376. while( *typeTag ) {
  377. switch( *typeTag++ ) {
  378. case ARRAY_BEGIN_TYPE_TAG:
  379. level += 1;
  380. break;
  381. case ARRAY_END_TYPE_TAG:
  382. if(level == 0)
  383. return result;
  384. level -= 1;
  385. break;
  386. default:
  387. if( level == 0 ) // only count items at level 0
  388. ++result;
  389. }
  390. }
  391. return result;
  392. }
  393. //------------------------------------------------------------------------------
  394. void ReceivedMessageArgumentIterator::Advance()
  395. {
  396. if( !value_.typeTagPtr_ )
  397. return;
  398. switch( *value_.typeTagPtr_++ ){
  399. case '\0':
  400. // don't advance past end
  401. --value_.typeTagPtr_;
  402. break;
  403. case TRUE_TYPE_TAG:
  404. case FALSE_TYPE_TAG:
  405. case NIL_TYPE_TAG:
  406. case INFINITUM_TYPE_TAG:
  407. // zero length
  408. break;
  409. case INT32_TYPE_TAG:
  410. case FLOAT_TYPE_TAG:
  411. case CHAR_TYPE_TAG:
  412. case RGBA_COLOR_TYPE_TAG:
  413. case MIDI_MESSAGE_TYPE_TAG:
  414. value_.argumentPtr_ += 4;
  415. break;
  416. case INT64_TYPE_TAG:
  417. case TIME_TAG_TYPE_TAG:
  418. case DOUBLE_TYPE_TAG:
  419. value_.argumentPtr_ += 8;
  420. break;
  421. case STRING_TYPE_TAG:
  422. case SYMBOL_TYPE_TAG:
  423. // we use the unsafe function FindStr4End(char*) here because all of
  424. // the arguments have already been validated in
  425. // ReceivedMessage::Init() below.
  426. value_.argumentPtr_ = FindStr4End( value_.argumentPtr_ );
  427. break;
  428. case BLOB_TYPE_TAG:
  429. {
  430. // treat blob size as an unsigned int for the purposes of this calculation
  431. uint32 blobSize = ToUInt32( value_.argumentPtr_ );
  432. value_.argumentPtr_ = value_.argumentPtr_ + osc::OSC_SIZEOF_INT32 + RoundUp4( blobSize );
  433. }
  434. break;
  435. case ARRAY_BEGIN_TYPE_TAG:
  436. case ARRAY_END_TYPE_TAG:
  437. // [ Indicates the beginning of an array. The tags following are for
  438. // data in the Array until a close brace tag is reached.
  439. // ] Indicates the end of an array.
  440. // zero length, don't advance argument ptr
  441. break;
  442. default: // unknown type tag
  443. // don't advance
  444. --value_.typeTagPtr_;
  445. break;
  446. }
  447. }
  448. //------------------------------------------------------------------------------
  449. ReceivedMessage::ReceivedMessage( const ReceivedPacket& packet )
  450. : addressPattern_( packet.Contents() )
  451. {
  452. Init( packet.Contents(), packet.Size() );
  453. }
  454. ReceivedMessage::ReceivedMessage( const ReceivedBundleElement& bundleElement )
  455. : addressPattern_( bundleElement.Contents() )
  456. {
  457. Init( bundleElement.Contents(), bundleElement.Size() );
  458. }
  459. bool ReceivedMessage::AddressPatternIsUInt32() const
  460. {
  461. return (addressPattern_[0] == '\0');
  462. }
  463. uint32 ReceivedMessage::AddressPatternAsUInt32() const
  464. {
  465. return ToUInt32( addressPattern_ );
  466. }
  467. void ReceivedMessage::Init( const char *message, osc_bundle_element_size_t size )
  468. {
  469. if( !IsValidElementSizeValue(size) )
  470. throw MalformedMessageException( "invalid message size" );
  471. if( size == 0 )
  472. throw MalformedMessageException( "zero length messages not permitted" );
  473. if( !IsMultipleOf4(size) )
  474. throw MalformedMessageException( "message size must be multiple of four" );
  475. const char *end = message + size;
  476. typeTagsBegin_ = FindStr4End( addressPattern_, end );
  477. if( typeTagsBegin_ == 0 ){
  478. // address pattern was not terminated before end
  479. throw MalformedMessageException( "unterminated address pattern" );
  480. }
  481. if( typeTagsBegin_ == end ){
  482. // message consists of only the address pattern - no arguments or type tags.
  483. typeTagsBegin_ = 0;
  484. typeTagsEnd_ = 0;
  485. arguments_ = 0;
  486. }else{
  487. if( *typeTagsBegin_ != ',' )
  488. throw MalformedMessageException( "type tags not present" );
  489. if( *(typeTagsBegin_ + 1) == '\0' ){
  490. // zero length type tags
  491. typeTagsBegin_ = 0;
  492. typeTagsEnd_ = 0;
  493. arguments_ = 0;
  494. }else{
  495. // check that all arguments are present and well formed
  496. arguments_ = FindStr4End( typeTagsBegin_, end );
  497. if( arguments_ == 0 ){
  498. throw MalformedMessageException( "type tags were not terminated before end of message" );
  499. }
  500. ++typeTagsBegin_; // advance past initial ','
  501. const char *typeTag = typeTagsBegin_;
  502. const char *argument = arguments_;
  503. unsigned int arrayLevel = 0;
  504. do{
  505. switch( *typeTag ){
  506. case TRUE_TYPE_TAG:
  507. case FALSE_TYPE_TAG:
  508. case NIL_TYPE_TAG:
  509. case INFINITUM_TYPE_TAG:
  510. // zero length
  511. break;
  512. // [ Indicates the beginning of an array. The tags following are for
  513. // data in the Array until a close brace tag is reached.
  514. // ] Indicates the end of an array.
  515. case ARRAY_BEGIN_TYPE_TAG:
  516. ++arrayLevel;
  517. // (zero length argument data)
  518. break;
  519. case ARRAY_END_TYPE_TAG:
  520. --arrayLevel;
  521. // (zero length argument data)
  522. break;
  523. case INT32_TYPE_TAG:
  524. case FLOAT_TYPE_TAG:
  525. case CHAR_TYPE_TAG:
  526. case RGBA_COLOR_TYPE_TAG:
  527. case MIDI_MESSAGE_TYPE_TAG:
  528. if( argument == end )
  529. throw MalformedMessageException( "arguments exceed message size" );
  530. argument += 4;
  531. if( argument > end )
  532. throw MalformedMessageException( "arguments exceed message size" );
  533. break;
  534. case INT64_TYPE_TAG:
  535. case TIME_TAG_TYPE_TAG:
  536. case DOUBLE_TYPE_TAG:
  537. if( argument == end )
  538. throw MalformedMessageException( "arguments exceed message size" );
  539. argument += 8;
  540. if( argument > end )
  541. throw MalformedMessageException( "arguments exceed message size" );
  542. break;
  543. case STRING_TYPE_TAG:
  544. case SYMBOL_TYPE_TAG:
  545. if( argument == end )
  546. throw MalformedMessageException( "arguments exceed message size" );
  547. argument = FindStr4End( argument, end );
  548. if( argument == 0 )
  549. throw MalformedMessageException( "unterminated string argument" );
  550. break;
  551. case BLOB_TYPE_TAG:
  552. {
  553. if( argument + osc::OSC_SIZEOF_INT32 > end )
  554. MalformedMessageException( "arguments exceed message size" );
  555. // treat blob size as an unsigned int for the purposes of this calculation
  556. uint32 blobSize = ToUInt32( argument );
  557. argument = argument + osc::OSC_SIZEOF_INT32 + RoundUp4( blobSize );
  558. if( argument > end )
  559. MalformedMessageException( "arguments exceed message size" );
  560. }
  561. break;
  562. default:
  563. throw MalformedMessageException( "unknown type tag" );
  564. }
  565. }while( *++typeTag != '\0' );
  566. typeTagsEnd_ = typeTag;
  567. if( arrayLevel != 0 )
  568. throw MalformedMessageException( "array was not terminated before end of message (expected ']' end of array tag)" );
  569. }
  570. // These invariants should be guaranteed by the above code.
  571. // we depend on them in the implementation of ArgumentCount()
  572. #ifndef NDEBUG
  573. std::ptrdiff_t argumentCount = typeTagsEnd_ - typeTagsBegin_;
  574. assert( argumentCount >= 0 );
  575. assert( argumentCount <= OSC_INT32_MAX );
  576. #endif
  577. }
  578. }
  579. //------------------------------------------------------------------------------
  580. ReceivedBundle::ReceivedBundle( const ReceivedPacket& packet )
  581. : elementCount_( 0 )
  582. {
  583. Init( packet.Contents(), packet.Size() );
  584. }
  585. ReceivedBundle::ReceivedBundle( const ReceivedBundleElement& bundleElement )
  586. : elementCount_( 0 )
  587. {
  588. Init( bundleElement.Contents(), bundleElement.Size() );
  589. }
  590. void ReceivedBundle::Init( const char *bundle, osc_bundle_element_size_t size )
  591. {
  592. if( !IsValidElementSizeValue(size) )
  593. throw MalformedBundleException( "invalid bundle size" );
  594. if( size < 16 )
  595. throw MalformedBundleException( "packet too short for bundle" );
  596. if( !IsMultipleOf4(size) )
  597. throw MalformedBundleException( "bundle size must be multiple of four" );
  598. if( bundle[0] != '#'
  599. || bundle[1] != 'b'
  600. || bundle[2] != 'u'
  601. || bundle[3] != 'n'
  602. || bundle[4] != 'd'
  603. || bundle[5] != 'l'
  604. || bundle[6] != 'e'
  605. || bundle[7] != '\0' )
  606. throw MalformedBundleException( "bad bundle address pattern" );
  607. end_ = bundle + size;
  608. timeTag_ = bundle + 8;
  609. const char *p = timeTag_ + 8;
  610. while( p < end_ ){
  611. if( p + osc::OSC_SIZEOF_INT32 > end_ )
  612. throw MalformedBundleException( "packet too short for elementSize" );
  613. // treat element size as an unsigned int for the purposes of this calculation
  614. uint32 elementSize = ToUInt32( p );
  615. if( (elementSize & ((uint32)0x03)) != 0 )
  616. throw MalformedBundleException( "bundle element size must be multiple of four" );
  617. p += osc::OSC_SIZEOF_INT32 + elementSize;
  618. if( p > end_ )
  619. throw MalformedBundleException( "packet too short for bundle element" );
  620. ++elementCount_;
  621. }
  622. if( p != end_ )
  623. throw MalformedBundleException( "bundle contents " );
  624. }
  625. uint64 ReceivedBundle::TimeTag() const
  626. {
  627. return ToUInt64( timeTag_ );
  628. }
  629. } // namespace osc