mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-31 11:19:18 +00:00
Replace std::snprintf and std::memcpy by std::stringstream and std::copy_n
This commit is contained in:
parent
cb7b53b7e9
commit
14edfdf206
@ -32,7 +32,6 @@
|
|||||||
#include <cmath> // for std::fmod, std::lround
|
#include <cmath> // for std::fmod, std::lround
|
||||||
#include <cstdlib> // for strtol
|
#include <cstdlib> // for strtol
|
||||||
#include <iostream> // for std::cout
|
#include <iostream> // for std::cout
|
||||||
#include <sstream> // for std::stringstream
|
|
||||||
|
|
||||||
|
|
||||||
Rtcm::Rtcm(uint16_t port) : RTCM_port(port), server_is_running(false)
|
Rtcm::Rtcm(uint16_t port) : RTCM_port(port), server_is_running(false)
|
||||||
|
@ -30,17 +30,18 @@
|
|||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
#include <glog/logging.h>
|
#include <glog/logging.h>
|
||||||
#include <algorithm> // for min
|
#include <algorithm> // for std::max, std::min, std::copy_n
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <cstddef> // for size_t
|
#include <cstddef> // for size_t
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring> // for memcpy
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include <iomanip> // for std::setw
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <sstream> // for std::stringstream
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -612,8 +613,10 @@ private:
|
|||||||
inline void encode_header()
|
inline void encode_header()
|
||||||
{
|
{
|
||||||
char header[header_length + 1] = "";
|
char header[header_length + 1] = "";
|
||||||
std::snprintf(header, header_length + 1, "GS%4d", std::max(std::min(static_cast<int>(body_length_), static_cast<int>(max_body_length)), 0));
|
std::stringstream ss;
|
||||||
std::memcpy(data_.data(), header, header_length);
|
ss << "GS" << std::setw(4) << std::max(std::min(static_cast<int>(body_length_), static_cast<int>(max_body_length)), 0);
|
||||||
|
std::copy_n(ss.str().c_str(), header_length + 1, header);
|
||||||
|
std::copy_n(header, header_length, data_.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -895,7 +898,7 @@ private:
|
|||||||
|
|
||||||
const char* char_msg = message.c_str();
|
const char* char_msg = message.c_str();
|
||||||
msg.body_length(message.length());
|
msg.body_length(message.length());
|
||||||
std::memcpy(msg.body(), char_msg, msg.body_length());
|
std::copy_n(char_msg, msg.body_length(), msg.body());
|
||||||
msg.encode_header();
|
msg.encode_header();
|
||||||
c->write(msg);
|
c->write(msg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user