inline size_t Packet_v<Ptr_type>::fill(const uint8_t* buffer, size_t length) { size_t rem = ip_capacity() - udp_length(); if(rem == 0) return 0; size_t total = std::min(length, rem); // copy from buffer to packet buffer memcpy(udp_data() + udp_data_length(), buffer, total); // set new packet length set_length(udp_data_length() + total); return total; }
PrintingStatus format_data(ctsConfig::StatusFormatting _format, long long _current_time, bool _clear_status) throw() { ctsUdpStatistics udp_data(ctsConfig::Settings->UdpStatusDetails.snap_view(_clear_status)); if (ctsConfig::StatusFormatting::Csv == _format) { unsigned long characters_written = 0; // converting milliseconds to seconds before printing characters_written += this->append_csvoutput(characters_written, TimeSliceLength, static_cast<float>(_current_time / 1000.0)); // calculating # of bytes that were received between the previous format() and current call to format() long long time_elapsed = udp_data.end_time.get() - udp_data.start_time.get(); characters_written += this->append_csvoutput( characters_written, BitsPerSecondLength, (time_elapsed > 0LL) ? static_cast<long long>(udp_data.bits_received.get() * 1000LL / time_elapsed) : 0LL); characters_written += this->append_csvoutput(characters_written, CompetedFramesLength, udp_data.successful_frames.get()); characters_written += this->append_csvoutput(characters_written, DroppedFramesLength, udp_data.dropped_frames.get()); characters_written += this->append_csvoutput(characters_written, RepeatFramesLength, udp_data.duplicate_frames.get()); characters_written += this->append_csvoutput(characters_written, RetryAttemptLength, udp_data.retry_attempts.get()); characters_written += this->append_csvoutput(characters_written, ErrorFramesLength, udp_data.error_frames.get(), false); // no comma at the end this->terminate_string(characters_written); } else { // converting milliseconds to seconds before printing this->right_justify_output(TimeSliceOffset, TimeSliceLength, static_cast<float>(_current_time / 1000.0)); // calculating # of bytes that were received between the previous format() and current call to format() long long time_elapsed = udp_data.end_time.get() - udp_data.start_time.get(); this->right_justify_output( BitsPerSecondOffset, BitsPerSecondLength, (time_elapsed > 0LL) ? static_cast<long long>(udp_data.bits_received.get() * 1000LL / time_elapsed) : 0LL); this->right_justify_output(CompetedFramesOffset, CompetedFramesLength, udp_data.successful_frames.get()); this->right_justify_output(DroppedFramesOffset, DroppedFramesLength, udp_data.dropped_frames.get()); this->right_justify_output(RepeatFramesOffset, RepeatFramesLength, udp_data.duplicate_frames.get()); this->right_justify_output(RetryAttemptOffset, RetryAttemptLength, udp_data.retry_attempts.get()); this->right_justify_output(ErrorFramesOffset, ErrorFramesLength, udp_data.error_frames.get()); this->terminate_string(ErrorFramesOffset); } return PrintComplete; }