Go to the documentation of this file.
52 using std::shared_ptr;
59 mode_(bagmode::
Write),
62 chunk_threshold_(768 * 1024),
70 curr_chunk_data_pos_(0),
72 decompressed_chunk_(0)
78 chunk_threshold_(768 * 1024),
86 curr_chunk_data_pos_(0),
88 decompressed_chunk_(0)
199 std::map<std::string, uint64_t> compression_counts;
200 std::map<std::string, uint64_t> compression_uncompressed;
201 std::map<std::string, uint64_t> compression_compressed;
207 seek(curr_chunk_info.pos);
221 auto chunk_count =
chunks_.size();
222 uint64_t main_compression_count = 0;
224 for (
auto&&
kvp : compression_counts)
226 if (
kvp.second > main_compression_count)
228 main_compression =
kvp.first;
229 main_compression_count =
kvp.second;
235 return std::make_tuple(main_compression, compressed, uncompressed);
267 char logtypename[100];
268 int version_major, version_minor;
269 #if defined(_MSC_VER)
270 if (sscanf_s(version_line.c_str(),
"#ROS%s V%d.%d", logtypename,
static_cast<unsigned>(
sizeof(logtypename)), &version_major, &version_minor) != 3)
272 if (sscanf(version_line.c_str(),
"#ROS%s V%d.%d", logtypename, &version_major, &version_minor) != 3)
276 version_ = version_major * 100 + version_minor;
334 for (
unsigned int i = 0;
i < chunk_info.connection_counts.size();
i++)
365 multiset<IndexEntry>
const&
index =
i->second;
392 std::vector<uint8_t> header_buffer;
398 write((
char*) &header_len, 4);
399 write((
char*) header_buffer.data(), header_len);
400 write((
char*) &data_len, 4);
405 padding.resize(data_len,
' ');
437 seek(data_size, std::ios::cur);
481 seek(end_of_chunk_pos);
494 switch (compression) {
536 multiset<IndexEntry>
const&
index =
i->second;
554 write((
char*) &
e.time.sec, 4);
555 write((
char*) &
e.time.nsec, 4);
556 write((
char*) &
e.offset, 4);
582 if (index_version != 0)
592 connection_info->
id = connection_id;
599 connection_id = topic_conn_id_iter->second;
607 read((
char*) &sec, 4);
608 read((
char*) &nsec, 4);
620 connection_index.insert(connection_index.end(), index_entry);
644 if (index_version != 1)
656 read((
char*) &sec, 4);
657 read((
char*) &nsec, 4);
668 connection_index.insert(connection_index.end(), index_entry);
727 connection_info->
id =
id;
729 connection_info->
header = std::make_shared<M_string>();
730 for (M_string::const_iterator
i = connection_header.
getValues()->begin();
i != connection_header.
getValues()->end();
i++)
731 (*connection_info->
header)[
i->first] =
i->second;
732 connection_info->
msg_def = (*connection_info->
header)[
"message_definition"];
734 connection_info->
md5sum = (*connection_info->
header)[
"md5sum"];
765 connection_info->
id =
id;
772 connection_info =
connections_[topic_conn_id_iter->second];
774 connection_info->
msg_def = message_definition;
777 connection_info->
header = std::make_shared<rs2rosinternal::M_string>();
779 (*connection_info->
header)[
"md5sum"] = connection_info->
md5sum;
780 (*connection_info->
header)[
"message_definition"] = connection_info->
msg_def;
926 uint32_t chunk_connection_count =
static_cast<uint32_t>(chunk_info.connection_counts.size());
936 chunk_info.start_time.sec, chunk_info.start_time.nsec,
937 chunk_info.end_time.sec, chunk_info.end_time.nsec);
943 for (map<uint32_t, uint32_t>::const_iterator
i = chunk_info.connection_counts.begin();
i != chunk_info.connection_counts.end();
i++) {
947 write((
char*) &connection_id, 4);
977 uint32_t chunk_connection_count = 0;
981 (
unsigned long long) chunk_info.
pos, chunk_connection_count,
986 for (
uint32_t i = 0;
i < chunk_connection_count;
i ++) {
987 uint32_t connection_id, connection_count;
988 read((
char*) &connection_id, 4);
989 read((
char*) &connection_count, 4);
1008 std::vector<uint8_t> header_buffer;
1011 write((
char*) &header_len, 4);
1012 write((
char*) header_buffer.data(), header_len);
1016 write((
char*) &data_len, 4);
1020 std::vector<uint8_t> header_buffer;
1026 buf.setSize(
buf.getSize() + 4 + header_len);
1028 memcpy(
buf.getData() +
offset, &header_len, 4);
1030 memcpy(
buf.getData() +
offset, header_buffer.data(), header_len);
1036 buf.setSize(
buf.getSize() + 4);
1038 memcpy(
buf.getData() +
offset, &data_len, 4);
1051 memcpy(&header_len, ptr, 4);
1056 bool parsed =
header.parse(ptr, header_len, error_msg);
1062 memcpy(&data_size, ptr, 4);
1070 total_bytes_read = 0;
1078 total_bytes_read += bytes_read;
1091 read((
char*) &header_len, 4);
1107 read((
char*) &data_size, 4);
1112 M_string::const_iterator fitr = fields.find(field);
1113 if (fitr == fields.end()) {
1117 else if ((fitr->second.size() < min_len) || (fitr->second.size() > max_len))
1129 M_string::const_iterator fitr =
checkField(fields, field_name, min_len, max_len,
required);
1130 if (fitr == fields.end())
1133 data = fitr->second;
1142 uint64_t bitmask = (1LL << 33) - 1;
std::vector< ChunkInfo > chunks_
std::string getFileName() const
return path of currently open file
const ROSTIME_DECL Time TIME_MIN
BagMode getMode() const
Get the mode the bag is in.
void setWriteMode(CompressionType type)
std::map< std::string, uint32_t > topic_connection_ids_
Time representation. May either represent wall clock time or ROS clock time.
static const std::string END_TIME_FIELD_NAME
CompressionType getCompression() const
Get the compression method to use for writing chunks.
uint32_t connection_count_
void read(char *b, std::streamsize n) const
std::string to_string(T value)
static const std::string COMPRESSION_NONE
static const unsigned char OP_CHUNK_INFO
uint32_t readMessageDataSize(IndexEntry const &index_entry) const
uint64_t decompressed_chunk_
position of decompressed chunk
void decompressBz2Chunk(ChunkHeader const &chunk_header) const
uint32_t getMajorVersion() const
Get the major-version of the open bag file.
void seek(uint64_t offset, int origin=std::ios_base::beg)
seek to given offset from origin
void setSize(uint32_t size)
rs2rosinternal::Time start_time
static const uint32_t FILE_HEADER_LENGTH
void appendHeaderToBuffer(Buffer &buf, rs2rosinternal::M_string const &fields)
GLboolean GLboolean GLboolean b
bool readDataLength(uint32_t &data_size) const
Buffer header_buffer_
reusable buffer in which to assemble the record header before writing to file
void openReadWrite(std::string const &filename)
open file for reading & writing
void readMessageDataHeaderFromBuffer(Buffer &buffer, uint32_t offset, rs2rosinternal::Header &header, uint32_t &data_size, uint32_t &bytes_read) const
GLsizei const GLchar *const * string
static const unsigned char OP_MSG_DATA
ChunkInfo curr_chunk_info_
static const uint32_t INDEX_VERSION
void decompressChunk(uint64_t chunk_pos) const
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
std::string toHeaderString(T const *field) const
static const uint32_t CHUNK_INFO_VERSION
void seek(uint64_t pos, int origin=std::ios_base::beg) const
uint32_t getChunkThreshold() const
Get the threshold for creating new chunks.
void write(std::string const &topic, rs2rosinternal::MessageEvent< T > const &event)
Write a message into the bag file.
std::map< rs2rosinternal::M_string, uint32_t > header_connection_ids_
void close()
Close the bag file.
void writeChunkInfoRecords()
std::map< uint32_t, ConnectionInfo * > connections_
void readChunkInfoRecord()
void decompressLz4Chunk(ChunkHeader const &chunk_header) const
rs2rosinternal::M_string::const_iterator checkField(rs2rosinternal::M_string const &fields, std::string const &field, unsigned int min_len, unsigned int max_len, bool required) const
uint32_t offset
absolute byte offset of the chunk record containing the message
BagMode
The possible modes to open a bag in.
uint64_t getOffset() const
return current offset from the beginning of the file
Base class for rosbag exceptions.
Buffer chunk_buffer_
reusable buffer to read chunk into
static const unsigned char OP_FILE_HEADER
static const unsigned char OP_CHUNK
void writeConnectionRecords()
void startReadingVersion200()
uint32_t getMinorVersion() const
Get the minor-version of the open bag file.
uint64_t chunk_pos
timestamp of the message
std::map< std::string, std::string > M_string
std::shared_ptr< rs2rosinternal::M_string > header
std::map< uint32_t, std::multiset< IndexEntry > > connection_indexes_
bool isOpen() const
return true if file is open for reading or writing
bool readHeader(rs2rosinternal::Header &header) const
void startWritingChunk(rs2rosinternal::Time time)
void appendConnectionRecordToBuffer(Buffer &buf, ConnectionInfo const *connection_info)
Exception thrown when on IO problems.
std::map< uint32_t, uint32_t > connection_counts
absolute byte offset of chunk record in bag file
uint64_t getSize() const
Get the current size of the bag file (a lower bound)
static const std::string CONNECTION_FIELD_NAME
void appendDataLengthToBuffer(Buffer &buf, uint32_t data_len)
uint32_t getChunkOffset() const
static const std::string MD5_FIELD_NAME
static const std::string INDEX_POS_FIELD_NAME
void setCompression(CompressionType compression)
Set the compression method to use for writing chunks.
unsigned __int64 uint64_t
rs2rosinternal::Time end_time
earliest timestamp of a message in the chunk
uint64_t file_header_pos_
void writeConnectionRecord(ConnectionInfo const *connection_info)
static const std::string START_TIME_FIELD_NAME
std::string getFileName() const
Get the filename of the bag.
uint32_t getCompressedBytesIn() const
return the number of bytes written to current compressed stream
const char * datatype()
returns DataType<M>::value();
void readMessageDataRecord102(uint64_t offset, rs2rosinternal::Header &header) const
bool readField(rs2rosinternal::M_string const &fields, std::string const &field_name, bool required, T *data) const
void writeHeader(rs2rosinternal::M_string const &fields)
static const std::string TOPIC_FIELD_NAME
const ROSTIME_DECL Time TIME_MAX
void close()
close the file
#define CONSOLE_BRIDGE_logDebug(fmt,...)
bool isOp(rs2rosinternal::M_string &fields, uint8_t reqOp) const
void openWrite(std::string const &filename)
open file for writing
::std_msgs::Time_< std::allocator< void > > Time
rs2rosinternal::Time time
std::tuple< std::string, uint64_t, uint64_t > getCompressionInfo() const
void decompress(CompressionType compression, uint8_t *dest, unsigned int dest_len, uint8_t *source, unsigned int source_len)
static const std::string DEF_FIELD_NAME
void readHeaderFromBuffer(Buffer &buffer, uint32_t offset, rs2rosinternal::Header &header, uint32_t &data_size, uint32_t &bytes_read) const
void writeDataLength(uint32_t data_len)
void readMessageDefinitionRecord102()
void writeChunkHeader(CompressionType compression, uint32_t compressed_size, uint32_t uncompressed_size)
static const std::string CONNECTION_COUNT_FIELD_NAME
std::map< uint32_t, std::multiset< IndexEntry > > curr_chunk_connection_indexes_
#define assert(condition)
void readTopicIndexRecord102()
void key(GLFWwindow *window, int k, int s, int action, int mods)
static const std::string VERSION
void startReadingVersion102()
void openAppend(std::string const &filename)
void openRead(std::string const &filename)
static const std::string CHUNK_POS_FIELD_NAME
static const std::string CHUNK_COUNT_FIELD_NAME
void readFileHeaderRecord()
void decompressRawChunk(ChunkHeader const &chunk_header) const
void openRead(std::string const &filename)
open file for reading
static const std::string TYPE_FIELD_NAME
static const std::string VER_FIELD_NAME
static const std::string COMPRESSION_LZ4
const char * md5sum()
returns MD5Sum<M>::value();
Buffer outgoing_chunk_buffer_
reusable buffer to read chunk into
void readChunkHeader(ChunkHeader &chunk_header) const
static const std::string COUNT_FIELD_NAME
void open(std::string const &filename, uint32_t mode=bagmode::Read)
Open a bag file.
static const unsigned char OP_MSG_DEF
void read(void *ptr, size_t size)
read size bytes from the file into ptr
CompressionType compression_
void setChunkThreshold(uint32_t chunk_threshold)
Set the threshold for creating new chunks.
static const std::string OP_FIELD_NAME
void write(std::string const &s)
uint64_t curr_chunk_data_pos_
Exception thrown on problems reading the bag index.
#define CONSOLE_BRIDGE_logError(fmt,...)
static const std::string COMPRESSION_FIELD_NAME
static const std::string SIZE_FIELD_NAME
void readConnectionIndexRecord200()
uint64_t pos
latest timestamp of a message in the chunk
bool truncate(uint64_t length)
Buffer decompress_buffer_
reusable buffer to decompress chunks into
Buffer record_buffer_
reusable buffer in which to assemble the record data before writing to file
GLenum GLuint GLenum GLsizei const GLchar * buf
static const unsigned char OP_CONNECTION
static const std::string COMPRESSION_BZ2
uint32_t chunk_threshold_
static const unsigned char OP_INDEX_DATA
void writeFileHeaderRecord()
void openWrite(std::string const &filename)
void readConnectionRecord()
rs2rosinternal::Header readMessageDataHeader(IndexEntry const &index_entry)
librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Fri Aug 2 2024 08:30:01