From d1f89c1eb52a08b97d5be5dd991c5991b6f0bf93 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期三, 21 四月 2021 16:41:30 +0800 Subject: [PATCH] 修改包名,作为go依赖库 --- src/proto.h | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/proto.h b/src/proto.h index da3bde6..2557f8e 100644 --- a/src/proto.h +++ b/src/proto.h @@ -19,17 +19,19 @@ #define PROTO_UA9UWKL1 #include "bhome_msg.pb.h" +#include "bhome_msg_api.pb.h" +#include <chrono> -using namespace bhome::msg; +using namespace bhome_msg; template <class Msg> struct MsgToType { }; -#define BHOME_MAP_MSG_AND_TYPE(mSG, tYPE) \ - template <> \ - struct MsgToType<mSG> { \ - static const bhome::msg::MsgType value = tYPE; \ +#define BHOME_MAP_MSG_AND_TYPE(mSG, tYPE) \ + template <> \ + struct MsgToType<mSG> { \ + static const MsgType value = tYPE; \ }; #define BHOME_SIMPLE_MAP_MSG(name) BHOME_MAP_MSG_AND_TYPE(Msg##name, kMsgType##name) @@ -50,7 +52,7 @@ #undef BHOME_MAP_MSG_AND_TYPE template <class Msg> -constexpr inline bhome::msg::MsgType GetType(const Msg &) +constexpr inline MsgType GetType(const Msg &) { return MsgToType<Msg>::value; } @@ -70,9 +72,20 @@ SetError(*msg.mutable_errmsg(), err_code, err_str); return msg; } - +std::string NewMsgId(); BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id, const std::string &msgid); BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id); // inline void AddRoute(BHMsgHead &head, const MQId &id) { head.add_route()->set_mq_id(&id, sizeof(id)); } inline bool IsSuccess(const ErrorCode ec) { return ec == eSuccess; } +bool IsMsgExpired(const BHMsgHead &head); + +inline int64_t CountSeconds(const std::chrono::steady_clock::time_point tp) +{ + return std::chrono::duration_cast<std::chrono::seconds>(tp.time_since_epoch()).count(); +} +inline int64_t NowSec() +{ + return CountSeconds(std::chrono::steady_clock::now()); +} + #endif // end of include guard: PROTO_UA9UWKL1 -- Gitblit v1.8.0