35 lines
909 B
C++
35 lines
909 B
C++
#include "PBUtils.h"
|
|
|
|
#include <boost/date_time/posix_time/conversion.hpp>
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
#include <google/protobuf/text_format.h>
|
|
#include <google/protobuf/timestamp.pb.h>
|
|
|
|
namespace bts {
|
|
namespace utils {
|
|
namespace pb {
|
|
|
|
std::string to_string(google::protobuf::Message const &msg) {
|
|
std::string result;
|
|
google::protobuf::TextFormat::PrintToString(msg, &result);
|
|
return result;
|
|
}
|
|
|
|
google::protobuf::Timestamp to_timestamp(datetime::PTime const &t) {
|
|
google::protobuf::Timestamp gts;
|
|
|
|
using namespace boost::posix_time;
|
|
using namespace boost::gregorian;
|
|
ptime timet_start(date(1970, 1, 1));
|
|
time_duration diff = t - timet_start;
|
|
|
|
gts.set_seconds(diff.total_seconds());
|
|
gts.set_nanos(
|
|
diff.total_nanoseconds() - (diff.total_seconds() * 1000 * 1000 * 1000));
|
|
return gts;
|
|
}
|
|
|
|
} // namespace pb
|
|
} // namespace utils
|
|
} // namespace bts
|