| | |
| | | |
| | | RefCount count_; |
| | | const uint32_t tag_ = kMsgTag; |
| | | const uint32_t size_ = 0; |
| | | const uint32_t capacity_ = 0; |
| | | const int64_t id_ = 0; |
| | | std::atomic<int64_t> timestamp_; |
| | | bool managed_ = false; |
| | | uint32_t size_ = 0; |
| | | Meta(uint32_t size) : |
| | | size_(size), id_(NewId()), timestamp_(NowSec()) {} |
| | | capacity_(size), id_(NewId()), timestamp_(NowSec()) {} |
| | | }; |
| | | OffsetType offset_; |
| | | static void *Alloc(const size_t size) |
| | |
| | | }; |
| | | Pack1(head_len, [&](void *p, int len) { head.SerializeToArray(p, len); }); |
| | | Pack1(body_len, [&](void *p, int len) { body.SerializeToArray(p, len); }); |
| | | meta()->size_ = 4 + head_len + 4 + body_len; |
| | | } |
| | | return addr; |
| | | } |
| | |
| | | void *addr = get(); |
| | | if (addr) { |
| | | memcpy(addr, content.data(), content.size()); |
| | | meta()->size_ = content.size(); |
| | | } |
| | | return addr; |
| | | } |
| | |
| | | uint32_t head_len = head.ByteSizeLong(); |
| | | uint32_t body_len = body.ByteSizeLong(); |
| | | uint32_t size = sizeof(head_len) + head_len + sizeof(body_len) + body_len; |
| | | return valid() && (meta()->size_ >= size) && Pack(head, head_len, body, body_len); |
| | | return valid() && (meta()->capacity_ >= size) && Pack(head, head_len, body, body_len); |
| | | } |
| | | |
| | | inline bool Make(const std::string &content) { return Make(content.size()) && Pack(content); } |
| | | inline bool Fill(const std::string &content) { return valid() && (meta()->size_ >= content.size()) && Pack(content); } |
| | | inline bool Fill(const std::string &content) { return valid() && (meta()->capacity_ >= content.size()) && Pack(content); } |
| | | |
| | | inline bool Make(const size_t size) { return Make(Alloc(size)); } |
| | | |
| | |
| | | p += 4; |
| | | return head.ParseFromArray(p, msg_size); |
| | | } |
| | | std::string content() const |
| | | { |
| | | auto p = get<char>(); |
| | | return p ? std::string(p, meta()->size_) : std::string(); |
| | | } |
| | | std::string body() const |
| | | { |
| | | auto p = get<char>(); |