types.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "errors.hpp"
4 #include "visibility.hpp"
5 #include <cstddef>
6 #include <functional>
7 #include <limits>
8 #include <memory>
9 #include <optional>
10 #include <string>
11 #include <unordered_map>
12 #include <vector>
13 
14 namespace mcap {
15 
16 #define MCAP_LIBRARY_VERSION "1.2.0"
17 
18 using SchemaId = uint16_t;
19 using ChannelId = uint16_t;
20 using Timestamp = uint64_t;
21 using ByteOffset = uint64_t;
22 using KeyValueMap = std::unordered_map<std::string, std::string>;
23 using ByteArray = std::vector<std::byte>;
24 using ProblemCallback = std::function<void(const Status&)>;
25 
26 constexpr char SpecVersion = '0';
28 constexpr uint8_t Magic[] = {137, 77, 67, 65, 80, SpecVersion, 13, 10}; // "\x89MCAP0\r\n"
29 constexpr uint64_t DefaultChunkSize = 1024 * 768;
30 constexpr ByteOffset EndOffset = std::numeric_limits<ByteOffset>::max();
31 constexpr Timestamp MaxTime = std::numeric_limits<Timestamp>::max();
32 
36 enum struct Compression {
37  None,
38  Lz4,
39  Zstd,
40 };
41 
47 enum struct CompressionLevel {
48  Fastest,
49  Fast,
50  Default,
51  Slow,
52  Slowest,
53 };
54 
58 enum struct OpCode : uint8_t {
59  Header = 0x01,
60  Footer = 0x02,
61  Schema = 0x03,
62  Channel = 0x04,
63  Message = 0x05,
64  Chunk = 0x06,
65  MessageIndex = 0x07,
66  ChunkIndex = 0x08,
67  Attachment = 0x09,
68  AttachmentIndex = 0x0A,
69  Statistics = 0x0B,
70  Metadata = 0x0C,
71  MetadataIndex = 0x0D,
72  SummaryOffset = 0x0E,
73  DataEnd = 0x0F,
74 };
75 
80 constexpr std::string_view OpCodeString(OpCode opcode);
81 
88  uint64_t dataSize;
89  std::byte* data;
90 
91  uint64_t recordSize() const {
92  return sizeof(opcode) + sizeof(dataSize) + dataSize;
93  }
94 };
95 
103  std::string profile;
104  std::string library;
105 };
106 
117  uint32_t summaryCrc;
118 
119  Footer() = default;
120  Footer(ByteOffset summaryStart, ByteOffset summaryOffsetStart)
121  : summaryStart(summaryStart)
122  , summaryOffsetStart(summaryOffsetStart)
123  , summaryCrc(0) {}
124 };
125 
133  std::string name;
134  std::string encoding;
136 
137  Schema() = default;
138 
139  Schema(const std::string_view name, const std::string_view encoding, const std::string_view data)
140  : name(name)
141  , encoding(encoding)
142  , data{reinterpret_cast<const std::byte*>(data.data()),
143  reinterpret_cast<const std::byte*>(data.data() + data.size())} {}
144 
145  Schema(const std::string_view name, const std::string_view encoding, const ByteArray& data)
146  : name(name)
147  , encoding(encoding)
148  , data{data} {}
149 };
150 
160  std::string topic;
161  std::string messageEncoding;
164 
165  Channel() = default;
166 
167  Channel(const std::string_view topic, const std::string_view messageEncoding, SchemaId schemaId,
168  const KeyValueMap& metadata = {})
169  : topic(topic)
170  , messageEncoding(messageEncoding)
171  , schemaId(schemaId)
172  , metadata(metadata) {}
173 };
174 
175 using SchemaPtr = std::shared_ptr<Schema>;
176 using ChannelPtr = std::shared_ptr<Channel>;
177 
187  uint32_t sequence;
201  uint64_t dataSize;
207  const std::byte* data = nullptr;
208 };
209 
218  uint32_t uncompressedCrc;
219  std::string compression;
221  const std::byte* records = nullptr;
222 };
223 
230  std::vector<std::pair<Timestamp, ByteOffset>> records;
231 };
232 
243  std::unordered_map<ChannelId, ByteOffset> messageIndexOffsets;
245  std::string compression;
248 };
249 
258  std::string name;
259  std::string mediaType;
260  uint64_t dataSize;
261  const std::byte* data = nullptr;
262  uint32_t crc;
263 };
264 
274  uint64_t dataSize;
275  std::string name;
276  std::string mediaType;
277 
278  AttachmentIndex() = default;
279  AttachmentIndex(const Attachment& attachment, ByteOffset fileOffset)
280  : offset(fileOffset)
281  , length(9 +
282  /* name */ 4 + attachment.name.size() +
283  /* log_time */ 8 +
284  /* create_time */ 8 +
285  /* media_type */ 4 + attachment.mediaType.size() +
286  /* data */ 8 + attachment.dataSize +
287  /* crc */ 4)
288  , logTime(attachment.logTime)
289  , createTime(attachment.createTime)
290  , dataSize(attachment.dataSize)
291  , name(attachment.name)
292  , mediaType(attachment.mediaType) {}
293 };
294 
300  uint64_t messageCount;
301  uint16_t schemaCount;
302  uint32_t channelCount;
303  uint32_t attachmentCount;
304  uint32_t metadataCount;
305  uint32_t chunkCount;
308  std::unordered_map<ChannelId, uint64_t> channelMessageCounts;
309 };
310 
316  std::string name;
318 };
319 
325  uint64_t offset;
326  uint64_t length;
327  std::string name;
328 
329  MetadataIndex() = default;
330  MetadataIndex(const Metadata& metadata, ByteOffset fileOffset);
331 };
332 
343 };
344 
350  uint32_t dataSectionCrc;
351 };
352 
355  std::optional<ByteOffset> chunkOffset;
356 
357  RecordOffset() = default;
358  explicit RecordOffset(ByteOffset offset_)
359  : offset(offset_) {}
360  RecordOffset(ByteOffset offset_, ByteOffset chunkOffset_)
361  : offset(offset_)
362  , chunkOffset(chunkOffset_) {}
363 
364  bool operator==(const RecordOffset& other) const;
365  bool operator>(const RecordOffset& other) const;
366 
367  bool operator!=(const RecordOffset& other) const {
368  return !(*this == other);
369  }
370  bool operator>=(const RecordOffset& other) const {
371  return ((*this == other) || (*this > other));
372  }
373  bool operator<(const RecordOffset& other) const {
374  return !(*this >= other);
375  }
376  bool operator<=(const RecordOffset& other) const {
377  return !(*this > other);
378  }
379 };
380 
388  const Message& message;
392 
393  MessageView(const Message& message, const ChannelPtr channel, const SchemaPtr schema,
394  RecordOffset offset)
395  : message(message)
396  , channel(channel)
397  , schema(schema)
398  , messageOffset(offset) {}
399 };
400 
401 } // namespace mcap
402 
403 #ifdef MCAP_IMPLEMENTATION
404 # include "types.inl"
405 #endif
mcap::RecordOffset::RecordOffset
RecordOffset(ByteOffset offset_)
Definition: types.hpp:358
mcap::ChunkIndex::messageIndexLength
ByteOffset messageIndexLength
Definition: types.hpp:244
mcap::RecordOffset::operator<=
bool operator<=(const RecordOffset &other) const
Definition: types.hpp:376
mcap::MessageView::channel
const ChannelPtr channel
Definition: types.hpp:389
mcap::Message::sequence
uint32_t sequence
An optional sequence number. If non-zero, sequence numbers should be unique per channel and increasin...
Definition: types.hpp:187
mcap::Attachment::name
std::string name
Definition: types.hpp:258
mcap::Compression
Compression
Supported MCAP compression algorithms.
Definition: types.hpp:36
mcap::ByteArray
std::vector< std::byte > ByteArray
Definition: types.hpp:23
mcap::AttachmentIndex::length
ByteOffset length
Definition: types.hpp:271
mcap::Statistics::metadataCount
uint32_t metadataCount
Definition: types.hpp:304
mcap::DataEnd::dataSectionCrc
uint32_t dataSectionCrc
Definition: types.hpp:350
mcap::RecordOffset::operator!=
bool operator!=(const RecordOffset &other) const
Definition: types.hpp:367
mcap::ChunkIndex::messageEndTime
Timestamp messageEndTime
Definition: types.hpp:240
mcap::ChunkIndex::messageStartTime
Timestamp messageStartTime
Definition: types.hpp:239
mcap::Status
Wraps a status code and string message carrying additional context.
Definition: errors.hpp:35
mcap::AttachmentIndex::mediaType
std::string mediaType
Definition: types.hpp:276
mcap::Timestamp
uint64_t Timestamp
Definition: types.hpp:20
mcap::Header::profile
std::string profile
Definition: types.hpp:103
mcap::MessageIndex::records
std::vector< std::pair< Timestamp, ByteOffset > > records
Definition: types.hpp:230
mcap::Statistics::channelCount
uint32_t channelCount
Definition: types.hpp:302
mcap::Chunk::compressedSize
ByteOffset compressedSize
Definition: types.hpp:220
mcap::Attachment::crc
uint32_t crc
Definition: types.hpp:262
mcap::CompressionLevel::Slow
@ Slow
errors.hpp
mcap::ChunkIndex
Chunk Index records are found in the Summary section, providing summary information for a single Chun...
Definition: types.hpp:238
mcap::MaxTime
constexpr Timestamp MaxTime
Definition: types.hpp:31
mcap::MessageIndex::channelId
ChannelId channelId
Definition: types.hpp:229
mcap::RecordOffset::chunkOffset
std::optional< ByteOffset > chunkOffset
Definition: types.hpp:355
mcap::Compression::Zstd
@ Zstd
mcap::ChunkIndex::chunkLength
ByteOffset chunkLength
Definition: types.hpp:242
mcap::CompressionLevel::Fastest
@ Fastest
mcap::Chunk
An collection of Schemas, Channels, and Messages that supports compression and indexing.
Definition: types.hpp:214
mcap::ChannelPtr
std::shared_ptr< Channel > ChannelPtr
Definition: types.hpp:176
MCAP_PUBLIC
#define MCAP_PUBLIC
Definition: visibility.hpp:22
mcap::Chunk::uncompressedSize
ByteOffset uncompressedSize
Definition: types.hpp:217
mcap::AttachmentIndex::AttachmentIndex
AttachmentIndex(const Attachment &attachment, ByteOffset fileOffset)
Definition: types.hpp:279
mcap::Statistics::messageEndTime
Timestamp messageEndTime
Definition: types.hpp:307
mcap::MetadataIndex::name
std::string name
Definition: types.hpp:327
mcap::EndOffset
constexpr ByteOffset EndOffset
Definition: types.hpp:30
mcap::AttachmentIndex::dataSize
uint64_t dataSize
Definition: types.hpp:274
mcap::RecordOffset
Definition: types.hpp:353
mcap::Record::opcode
OpCode opcode
Definition: types.hpp:87
mcap::MessageView::messageOffset
const RecordOffset messageOffset
Definition: types.hpp:391
mcap::Footer::summaryOffsetStart
ByteOffset summaryOffsetStart
Definition: types.hpp:116
mcap::Footer
The final record in an MCAP file (before the trailing magic byte sequence). Contains byte offsets fro...
Definition: types.hpp:114
mcap::Attachment::mediaType
std::string mediaType
Definition: types.hpp:259
mcap::Chunk::compression
std::string compression
Definition: types.hpp:219
nonstd::span_lite::size
span_constexpr std::size_t size(span< T, Extent > const &spn)
Definition: span.hpp:1554
mcap::Schema::data
ByteArray data
Definition: types.hpp:135
mcap::SummaryOffset::groupLength
ByteOffset groupLength
Definition: types.hpp:342
mcap::Footer::summaryCrc
uint32_t summaryCrc
Definition: types.hpp:117
mcap::RecordOffset::offset
ByteOffset offset
Definition: types.hpp:354
mcap::Statistics::messageCount
uint64_t messageCount
Definition: types.hpp:300
mcap::Channel::messageEncoding
std::string messageEncoding
Definition: types.hpp:161
start_test_publisher.topic
topic
Definition: start_test_publisher.py:22
mcap::MessageView
Returned when iterating over Messages in a file, MessageView contains a reference to one Message,...
Definition: types.hpp:387
mcap::Attachment::createTime
Timestamp createTime
Definition: types.hpp:257
mcap::MessageView::MessageView
MessageView(const Message &message, const ChannelPtr channel, const SchemaPtr schema, RecordOffset offset)
Definition: types.hpp:393
mcap::SummaryOffset
Summary Offset records are found in the Summary Offset section. Records in the Summary section are gr...
Definition: types.hpp:339
mcap::OpCodeString
constexpr MCAP_PUBLIC std::string_view OpCodeString(OpCode opcode)
Get the string representation of an OpCode.
mcap::Channel
Describes a Channel that messages are written to. A Channel represents a single connection from a pub...
Definition: types.hpp:158
mcap::LibraryVersion
constexpr char LibraryVersion[]
Definition: types.hpp:27
MCAP_LIBRARY_VERSION
#define MCAP_LIBRARY_VERSION
Definition: types.hpp:16
mcap::Statistics::messageStartTime
Timestamp messageStartTime
Definition: types.hpp:306
mcap::Message::publishTime
Timestamp publishTime
Nanosecond timestamp when this message was initially published. If not available, this should be set ...
Definition: types.hpp:197
mcap::ChunkIndex::chunkStartOffset
ByteOffset chunkStartOffset
Definition: types.hpp:241
mcap::Channel::schemaId
SchemaId schemaId
Definition: types.hpp:162
mcap::Schema::id
SchemaId id
Definition: types.hpp:132
operator==
bool operator==(QwtEventPattern::MousePattern b1, QwtEventPattern::MousePattern b2)
Compare operator.
Definition: qwt_event_pattern.h:228
mcap::ByteOffset
uint64_t ByteOffset
Definition: types.hpp:21
mcap::CompressionLevel::Default
@ Default
mcap::Attachment
An Attachment is an arbitrary file embedded in an MCAP file, including a name, media type,...
Definition: types.hpp:255
visibility.hpp
mcap::Magic
constexpr uint8_t Magic[]
Definition: types.hpp:28
nlohmann::detail::void
j template void())
Definition: json.hpp:4061
mcap::MetadataIndex::length
uint64_t length
Definition: types.hpp:326
mcap::MetadataIndex
Metadata Index records are found in the Summary section, providing summary information for a single M...
Definition: types.hpp:324
mcap::MetadataIndex::offset
uint64_t offset
Definition: types.hpp:325
mcap
Definition: crc32.hpp:5
mcap::CompressionLevel
CompressionLevel
Compression level to use when compression is enabled. Slower generally produces smaller files,...
Definition: types.hpp:47
mcap::Message::dataSize
uint64_t dataSize
Size of the message payload in bytes, pointed to via data.
Definition: types.hpp:201
mcap::SchemaPtr
std::shared_ptr< Schema > SchemaPtr
Definition: types.hpp:175
mcap::CompressionLevel::Slowest
@ Slowest
mcap::Channel::topic
std::string topic
Definition: types.hpp:160
string_view
basic_string_view< char > string_view
Definition: core.h:518
mcap::CompressionLevel::Fast
@ Fast
mcap::Schema::name
std::string name
Definition: types.hpp:133
mcap::Footer::Footer
Footer(ByteOffset summaryStart, ByteOffset summaryOffsetStart)
Definition: types.hpp:120
mcap::RecordOffset::operator>=
bool operator>=(const RecordOffset &other) const
Definition: types.hpp:370
mcap::MessageView::schema
const SchemaPtr schema
Definition: types.hpp:390
mcap::Chunk::messageEndTime
Timestamp messageEndTime
Definition: types.hpp:216
mcap::Record::data
std::byte * data
Definition: types.hpp:89
mcap::AttachmentIndex::name
std::string name
Definition: types.hpp:275
mcap::ChunkIndex::messageIndexOffsets
std::unordered_map< ChannelId, ByteOffset > messageIndexOffsets
Definition: types.hpp:243
mcap::Metadata
Holds a named map of key/value strings containing arbitrary user data. Metadata records are found in ...
Definition: types.hpp:315
mcap::Message::channelId
ChannelId channelId
Definition: types.hpp:182
mcap::Statistics::attachmentCount
uint32_t attachmentCount
Definition: types.hpp:303
OpCode
OpCode
Definition: lopcodes.h:196
mcap::Schema::Schema
Schema(const std::string_view name, const std::string_view encoding, const std::string_view data)
Definition: types.hpp:139
mcap::Statistics
The Statistics record is found in the Summary section, providing counts and timestamp ranges for the ...
Definition: types.hpp:299
mcap::Record::recordSize
uint64_t recordSize() const
Definition: types.hpp:91
mcap::Metadata::metadata
KeyValueMap metadata
Definition: types.hpp:317
mcap::AttachmentIndex::logTime
Timestamp logTime
Definition: types.hpp:272
mcap::Header
Appears at the beginning of every MCAP file (after the magic byte sequence) and contains the recordin...
Definition: types.hpp:102
mcap::Compression::Lz4
@ Lz4
mcap::RecordOffset::RecordOffset
RecordOffset(ByteOffset offset_, ByteOffset chunkOffset_)
Definition: types.hpp:360
mcap::Chunk::messageStartTime
Timestamp messageStartTime
Definition: types.hpp:215
mcap::Attachment::logTime
Timestamp logTime
Definition: types.hpp:256
mcap::Metadata::name
std::string name
Definition: types.hpp:316
mcap::Message
A single Message published to a Channel.
Definition: types.hpp:181
mcap::Message::logTime
Timestamp logTime
Nanosecond timestamp when this message was recorded or received for recording.
Definition: types.hpp:192
mcap::SummaryOffset::groupOpCode
OpCode groupOpCode
Definition: types.hpp:340
mcap::ChunkIndex::compression
std::string compression
Definition: types.hpp:245
mcap::DefaultChunkSize
constexpr uint64_t DefaultChunkSize
Definition: types.hpp:29
mcap::Record
A generic Type-Length-Value record using a uint8 type and uint64 length. This is the generic form of ...
Definition: types.hpp:86
mqtt_test.data
dictionary data
Definition: mqtt_test.py:22
mcap::ProblemCallback
std::function< void(const Status &)> ProblemCallback
Definition: types.hpp:24
mcap::Statistics::chunkCount
uint32_t chunkCount
Definition: types.hpp:305
mcap::Channel::metadata
KeyValueMap metadata
Definition: types.hpp:163
mcap::Attachment::dataSize
uint64_t dataSize
Definition: types.hpp:260
sol::operator>
constexpr bool operator>(const optional< T > &lhs, const optional< U > &rhs)
\group relop
Definition: sol.hpp:6030
mcap::RecordOffset::operator<
bool operator<(const RecordOffset &other) const
Definition: types.hpp:373
mcap::Footer::summaryStart
ByteOffset summaryStart
Definition: types.hpp:115
mcap::Schema::encoding
std::string encoding
Definition: types.hpp:134
mcap::AttachmentIndex::createTime
Timestamp createTime
Definition: types.hpp:273
mcap::MessageView::message
const Message & message
Definition: types.hpp:388
mcap::OpCode
OpCode
MCAP record types.
Definition: types.hpp:58
mcap::MessageIndex
A list of timestamps to byte offsets for a single Channel. This record appears after each Chunk,...
Definition: types.hpp:228
mcap::DataEnd
The final record in the Data section, signaling the end of Data and beginning of Summary....
Definition: types.hpp:349
mcap::Schema
Describes a schema used for message encoding and decoding and/or describing the shape of messages....
Definition: types.hpp:131
mcap::AttachmentIndex::offset
ByteOffset offset
Definition: types.hpp:270
mcap::KeyValueMap
std::unordered_map< std::string, std::string > KeyValueMap
Definition: types.hpp:22
mcap::Statistics::schemaCount
uint16_t schemaCount
Definition: types.hpp:301
mcap::Record::dataSize
uint64_t dataSize
Definition: types.hpp:88
mcap::Chunk::uncompressedCrc
uint32_t uncompressedCrc
Definition: types.hpp:218
mcap::Channel::id
ChannelId id
Definition: types.hpp:159
mcap::SpecVersion
constexpr char SpecVersion
Definition: types.hpp:26
mcap::AttachmentIndex
Attachment Index records are found in the Summary section, providing summary information for a single...
Definition: types.hpp:269
mcap::Header::library
std::string library
Definition: types.hpp:104
mcap::ChunkIndex::compressedSize
ByteOffset compressedSize
Definition: types.hpp:246
mcap::Channel::Channel
Channel(const std::string_view topic, const std::string_view messageEncoding, SchemaId schemaId, const KeyValueMap &metadata={})
Definition: types.hpp:167
mcap::Compression::None
@ None
mcap::SummaryOffset::groupStart
ByteOffset groupStart
Definition: types.hpp:341
mcap::Statistics::channelMessageCounts
std::unordered_map< ChannelId, uint64_t > channelMessageCounts
Definition: types.hpp:308
mcap::SchemaId
uint16_t SchemaId
Definition: types.hpp:18
mcap::ChunkIndex::uncompressedSize
ByteOffset uncompressedSize
Definition: types.hpp:247
mcap::ChannelId
uint16_t ChannelId
Definition: types.hpp:19
mcap::Schema::Schema
Schema(const std::string_view name, const std::string_view encoding, const ByteArray &data)
Definition: types.hpp:145


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:48