51 lines
1.0 KiB
C++
Executable File
51 lines
1.0 KiB
C++
Executable File
#pragma once
|
|
|
|
#include <string>
|
|
#include <google/protobuf/text_format.h>
|
|
#include <google/protobuf/timestamp.pb.h>
|
|
#include <sys/time.h>
|
|
#include "lib/utils/datetime.h"
|
|
#include "lib/utils/bts_assert.h"
|
|
#include "bts_export.h"
|
|
|
|
namespace google {
|
|
namespace protobuf {
|
|
class Message;
|
|
class Timestamp;
|
|
}}
|
|
|
|
namespace bts {
|
|
namespace utils {
|
|
namespace pb {
|
|
|
|
BTS_EXPORT std::string to_string (google::protobuf::Message const &msg);
|
|
BTS_EXPORT google::protobuf::Timestamp to_timestamp(datetime::PTime const &ptime);
|
|
|
|
template <class T> bool from_string(const std::string &str, T*out)
|
|
{
|
|
return google::protobuf::TextFormat::ParseFromString (str,out);
|
|
}
|
|
|
|
template <class T> T from_string(const std::string &str)
|
|
{
|
|
T result;
|
|
bts_assert(google::protobuf::TextFormat::ParseFromString (str,&result));
|
|
return result;
|
|
}
|
|
|
|
google::protobuf::Timestamp pb_now()
|
|
{
|
|
::google::protobuf::Timestamp result;
|
|
struct timeval tv;
|
|
gettimeofday(&tv, NULL);
|
|
result.set_seconds(tv.tv_sec);
|
|
result.set_nanos(tv.tv_usec * 1000);
|
|
return result;
|
|
}
|
|
|
|
}}}
|
|
|
|
|
|
|
|
|