30constexpr uint32_t
INT_BITS =
static_cast<uint32_t
>(
sizeof(uint32_t) * 8);
38 std::shared_ptr<cyber::Node> node) = 0;
46 virtual char *
GetBuf(
size_t offset) = 0;
54 : topic_name_(topic_name) {}
59 std::shared_ptr<cyber::Node> node);
67 virtual char *
GetBuf(
size_t offset) {
return proto_buf_ + offset; }
68 virtual uint32_t
GetMsgID()
const {
return sequence_num_; }
69 virtual std::string
GetMsgName()
const {
return proto_name_; }
72 size_t total_frames_ = 0;
73 size_t total_size_ = 0;
74 std::string proto_name_ =
"";
75 std::vector<uint32_t> status_list_;
76 char *proto_buf_ =
nullptr;
77 bool is_ready_diser =
false;
78 uint32_t sequence_num_ = 0;
79 std::shared_ptr<cyber::Writer<T>> writer_;
80 std::string topic_name_ =
"";
90 if (!proto_buf_ || !proto) {
93 proto->ParseFromArray(proto_buf_,
static_cast<int>(total_size_));
99 size_t status_size = status_list_.size();
100 uint32_t status_index = frame_index /
INT_BITS;
101 if (status_size == 0 ||
102 static_cast<std::size_t
>(status_index) >= status_size) {
103 is_ready_diser =
false;
107 status_list_[status_index] |= (1 << (frame_index %
INT_BITS));
108 for (
size_t i = 0; i < status_size; i++) {
109 if (i == status_size - 1) {
110 if (
static_cast<int>(status_list_[i]) ==
111 (1 << total_frames_ %
INT_BITS) - 1) {
112 AINFO <<
"diserialized is ready";
113 is_ready_diser =
true;
115 is_ready_diser =
false;
119 if (status_list_[i] != 0xffffffff) {
120 is_ready_diser =
false;
123 is_ready_diser =
true;
130 if (strcmp(proto_name_.c_str(), header.
GetMsgName().c_str()) == 0 &&
131 sequence_num_ == header.
GetMsgID()) {
143 if (total_frames_ == 0) {
146 int status_size =
static_cast<int>(total_frames_ /
INT_BITS +
147 ((total_frames_ %
INT_BITS) ? 1 : 0));
148 if (status_list_.empty()) {
149 for (
int i = 0; i < status_size; i++) {
150 status_list_.push_back(0);
156 proto_buf_ =
new char[total_size_];
157 }
catch (
const std::bad_alloc& e) {
158 AERROR <<
"Memory allocation failed: " << e.what();
167 const BridgeHeader &header, std::shared_ptr<cyber::Node> node) {
168 writer_ = node->CreateWriter<T>(topic_name_.c_str());
169 return Initialize(header);
174 auto pb_msg = std::make_shared<T>();
175 if (!Diserialized(pb_msg)) {
178 writer_->Write(pb_msg);
virtual uint32_t GetMsgID() const
virtual bool Initialize(const BridgeHeader &header, std::shared_ptr< cyber::Node > node)
bool Diserialized(std::shared_ptr< T > proto)
virtual bool IsTheProto(const BridgeHeader &header)
BridgeProtoDiserializedBuf(const std::string &topic_name)
virtual std::string GetMsgName() const
virtual bool DiserializedAndPub()
virtual void UpdateStatus(uint32_t frame_index)
virtual bool IsReadyDiserialize() const
virtual ~BridgeProtoDiserializedBuf()
virtual char * GetBuf(size_t offset)
BridgeProtoDiserializedBuf()
virtual uint32_t GetMsgID() const =0
virtual char * GetBuf(size_t offset)=0
virtual bool DiserializedAndPub()=0
virtual void UpdateStatus(uint32_t frame_index)=0
virtual bool Initialize(const BridgeHeader &header, std::shared_ptr< cyber::Node > node)=0
virtual std::string GetMsgName() const =0
ProtoDiserializedBufBase()
virtual bool IsTheProto(const BridgeHeader &header)=0
virtual ~ProtoDiserializedBufBase()
virtual bool IsReadyDiserialize() const =0
constexpr uint32_t INT_BITS