void SendAutoBundle() { if (_autoBundleMessageBuffer.count == 0) { return; } // Prepare for composing bundle. _bundleTimeTag.time = _dateTime; int sendBufferByteIndex = 0; OscBundle.TryWriteHeader(_bundleTimeTag, _sendBuffer, ref sendBufferByteIndex); // Loop through serialized messages in the end-of-frame-buffer. int messageBufferByteIndex = 0; for (int m = 0; m < _autoBundleMessageBuffer.count; m++) { // Get message size. int messageSize = _autoBundleMessageBuffer.GetSize(m); // Bundle stores size of each message in a 4 byte integer. // Check limit. if (sendBufferByteIndex + FourByteOscData.byteCount + messageSize >= _sendBuffer.Length) { // We have reached the safety limit, now send the bundle. TrySendBuffer(sendBufferByteIndex); // Get ready for composing next bundle. sendBufferByteIndex = OscConst.bundleHeaderSize; } // Write message size and data. new FourByteOscData(messageSize).TryWriteTo(_sendBuffer, ref sendBufferByteIndex); Array.Copy(_autoBundleMessageBuffer.data, messageBufferByteIndex, _sendBuffer, sendBufferByteIndex, messageSize); messageBufferByteIndex += messageSize; sendBufferByteIndex += messageSize; } // Send bundle if there is anything in it and clean. if (sendBufferByteIndex > OscConst.bundleHeaderSize) { TrySendBuffer(sendBufferByteIndex); } _messageCountThisFrame += _autoBundleMessageBuffer.count; _autoBundleMessageBuffer.Clear(); }
IEnumerator SendBundleOnEndOfFrame() { while (_bundleMessagesOnEndOfFrame) { // Wait. yield return(_endOfFrameYield); // Prepare for composing bundle. _endOfFrameTimeTag.time = _dateTime; int cacheIndex = 0; OscBundle.TryWriteHeader(_endOfFrameTimeTag, _cache, ref cacheIndex); // Loop through serialized messages in the end-of-frame-buffer. int bufferIndex = 0; for (int m = 0; m < _endOfFrameBuffer.count; m++) { // Compute size. int messageSize = _endOfFrameBuffer.GetSize(m); // Bundle stores size of each message in a 4 byte integer. // Check limit. if (_splitBundlesAvoidingBufferOverflow && cacheIndex + FourByteOscData.byteCount + messageSize >= _udpBufferSize) { // We have reached the safelty limit, now send the bundle. TrySendCache(cacheIndex); // Get ready for composing next bundle. cacheIndex = OscConst.bundleHeaderSize; } // Write message size and data. new FourByteOscData(messageSize).TryWriteTo(_cache, ref cacheIndex); Buffer.BlockCopy(_endOfFrameBuffer.data, bufferIndex, _cache, cacheIndex, messageSize); bufferIndex += messageSize; cacheIndex += messageSize; } // Send bundle if there is anything in it and clean. if (cacheIndex > OscConst.bundleHeaderSize) { TrySendCache(cacheIndex); } _endOfFrameBuffer.Clear(); } _endOfFrameCoroutine = null; }