| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #ifndef DEPTHGUIDE_FRAG_BASIC_H
- #define DEPTHGUIDE_FRAG_BASIC_H
- #include "frag_base.hpp"
- #include <boost/dynamic_bitset.hpp>
- #include <list>
- class frag_basic : public frag_base {
- public:
- using frag_base::frag_base;
- bool send(const data_type &data) override;
- size_t max_length() const override { return UINT32_MAX; }
- private:
- struct frag_header_type {
- uint32_t msg_id = 0;
- uint32_t msg_size = 0;
- uint32_t bl_num = 0;
- uint32_t bl_id = 0;
- uint32_t bl_offset = 0;
- using header_size_type = uint8_t;
- static constexpr header_size_type header_size = 5 * sizeof(uint32_t);
- static constexpr size_t extra_size = header_size + sizeof(header_size);
- template<typename ReaderType>
- void fill_from(ReaderType &reader) {
- reader >> msg_id >> msg_size >> bl_num >> bl_id >> bl_offset;
- }
- template<typename WriterType>
- void write_to(WriterType &writer) {
- writer << msg_id << msg_size << bl_num << bl_id << bl_offset;
- }
- };
- // for sending message
- uint32_t last_send_id = 0;
- // for receiving message
- using bitset_type = boost::dynamic_bitset<>;
- struct msg_info : boost::noncopyable {
- uint32_t msg_id = 0;
- bitset_type bl_ok;
- data_type data;
- size_t bytes_ok = 0;
- explicit msg_info(frag_header_type header)
- : bl_ok(header.bl_num), data(header.msg_size) {
- msg_id = header.msg_id;
- }
- bool verify(frag_header_type header) const;
- bool is_complete() const;
- void merge(frag_header_type header, const data_type &data);
- };
- using queue_type = std::list<msg_info>;
- uint32_t last_recv_id = 0; // id of last returned message
- queue_type msg_q; // message queue
- void append_data(const data_type &data) override;
- };
- #endif //DEPTHGUIDE_FRAG_BASIC_H
|