Skip to content

Commit be318d4

Browse files
committed
Optional zstd compression
1 parent c89d9cd commit be318d4

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ file(
9090
WRITE
9191
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
9292
"include(\"\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake\")\n"
93+
"include(CMakeFindDependencyMacro)\n"
94+
"find_dependency(zstd REQUIRED)\n"
9395
)
9496

9597
install(

include/pjmsg_mcap_wrapper/all.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
@author Alexander Sherikov
44
@copyright 2024 Alexander Sherikov. Licensed under the Apache License,
55
Version 2.0. (see LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
6-
7-
@brief Sink class.
86
*/
97

108
#pragma once
119

1210
#include <filesystem>
1311
#include <vector>
1412

15-
#define PJMSG_MCAP_WRAPPER_PUBLIC __attribute__((visibility("default")))
16-
13+
#ifndef PJMSG_MCAP_WRAPPER_PUBLIC
14+
# define PJMSG_MCAP_WRAPPER_PUBLIC __attribute__((visibility("default")))
15+
#endif
1716

1817
namespace pjmsg_mcap_wrapper
1918
{
@@ -47,6 +46,18 @@ namespace pjmsg_mcap_wrapper
4746

4847
class PJMSG_MCAP_WRAPPER_PUBLIC Writer
4948
{
49+
public:
50+
struct PJMSG_MCAP_WRAPPER_PUBLIC Parameters
51+
{
52+
enum class PJMSG_MCAP_WRAPPER_PUBLIC Compression
53+
{
54+
NONE,
55+
ZSTD
56+
} compression_ = Compression::NONE;
57+
58+
Parameters(){};
59+
};
60+
5061
protected:
5162
class Implementation;
5263

@@ -56,7 +67,10 @@ namespace pjmsg_mcap_wrapper
5667
public:
5768
Writer();
5869
~Writer();
59-
void initialize(const std::filesystem::path &filename, const std::string &topic_prefix);
70+
void initialize(
71+
const std::filesystem::path &filename,
72+
const std::string &topic_prefix,
73+
const Parameters &params = Parameters{});
6074
void flush();
6175
void write(const Message &message);
6276
};

package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<author email="alexander@sherikov.net">Alexander Sherikov</author>
88
<license>Apache 2.0</license>
99

10+
<buildtool_depend>cmake</buildtool_depend>
11+
<depend>libzstd-dev</depend>
12+
1013
<export>
1114
<build_type>cmake</build_type>
1215
</export>

src/writer.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#define MCAP_IMPLEMENTATION
1717
#define MCAP_COMPRESSION_NO_LZ4
18-
#define MCAP_COMPRESSION_NO_ZSTD
1918
#define MCAP_PUBLIC __attribute__((visibility("hidden")))
2019

2120
#pragma GCC diagnostic push
@@ -241,12 +240,28 @@ namespace pjmsg_mcap_wrapper
241240
writer_.close();
242241
}
243242

244-
void initialize(const std::filesystem::path &filename, const std::string &topic_prefix)
243+
void initialize(
244+
const std::filesystem::path &filename,
245+
const std::string &topic_prefix,
246+
const Writer::Parameters &params)
245247
{
246248
{
247249
mcap::McapWriterOptions options = mcap::McapWriterOptions("ros2msg");
248-
/// @todo needed if compression is used, delays writing
249-
options.noChunking = true;
250+
251+
// Set compression based on parameters
252+
switch (params.compression_)
253+
{
254+
case Writer::Parameters::Compression::ZSTD:
255+
options.noChunking = false;
256+
options.compression = mcap::Compression::Zstd;
257+
break;
258+
case Writer::Parameters::Compression::NONE:
259+
default:
260+
options.noChunking = true;
261+
options.compression = mcap::Compression::None;
262+
break;
263+
}
264+
250265
const mcap::Status res = writer_.open(filename.native(), options);
251266
if (not res.ok())
252267
{
@@ -279,9 +294,12 @@ namespace pjmsg_mcap_wrapper
279294

280295
Writer::~Writer() = default;
281296

282-
void Writer::initialize(const std::filesystem::path &filename, const std::string &topic_prefix)
297+
void Writer::initialize(
298+
const std::filesystem::path &filename,
299+
const std::string &topic_prefix,
300+
const Writer::Parameters &params)
283301
{
284-
pimpl_->initialize(filename, topic_prefix);
302+
pimpl_->initialize(filename, topic_prefix, params);
285303
}
286304

287305
void Writer::flush()

0 commit comments

Comments
 (0)