From 4d468f931c258eb1f57b7ea304b8885fb52b0fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 3 Aug 2023 10:25:46 +0200 Subject: [PATCH 1/3] simple_writer: add Windows support for fsync --- README.md | 2 +- ulog_cpp/simple_writer.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b002f6..584b344 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Streamed C++ [ULog](https://docs.px4.io/main/en/dev_log/ulog_file_format.html) r ## Properties - Options for keeping log data in memory or processing immediately. -- Pure C++17 without additional dependencies (`SimpleWriter` requires POSIX for file IO). +- Pure C++17 without additional dependencies (`SimpleWriter` requires platform-specific `fsync`/`FlushFileBuffers`). - The reader is ~10 times as fast compared to the [python implementation](https://github.com/PX4/pyulog). However, the API is more low-level, and if you're just looking for an easy-to-use parsing library, use pyulog. - Unsupported ULog features: diff --git a/ulog_cpp/simple_writer.cpp b/ulog_cpp/simple_writer.cpp index 45b8ef0..0651859 100644 --- a/ulog_cpp/simple_writer.cpp +++ b/ulog_cpp/simple_writer.cpp @@ -5,7 +5,11 @@ #include "simple_writer.hpp" +#ifdef WINDOWS +#include +#else #include +#endif namespace ulog_cpp { @@ -108,7 +112,11 @@ void SimpleWriter::fsync() { if (_file) { fflush(_file); +#ifdef WINDOWS + FlushFileBuffers(static_cast(_fileno(_file))); +#else ::fsync(fileno(_file)); +#endif } } uint16_t SimpleWriter::writeAddLoggedMessage(const std::string& message_format_name, From 70930944fdd2f1ab6bca17d3c50bf57361561c22 Mon Sep 17 00:00:00 2001 From: Holden <68555040+HTRamsey@users.noreply.github.com> Date: Mon, 19 Aug 2024 04:31:38 -0400 Subject: [PATCH 2/3] fix Windows Build (#10) - Fix portability of vector iterator - Fix casting to HANDLE --- ulog_cpp/messages.cpp | 2 +- ulog_cpp/simple_writer.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ulog_cpp/messages.cpp b/ulog_cpp/messages.cpp index 776b5f0..c5c82fd 100644 --- a/ulog_cpp/messages.cpp +++ b/ulog_cpp/messages.cpp @@ -278,7 +278,7 @@ Value::NativeTypeVariant Value::asNativeTypeVariant() const if (_backing_ref_end - string_start_iterator < _field_ref.arrayLength()) { throw AccessException("Decoding fault, memory too short"); } - int string_length = strnlen(string_start_iterator.base(), _field_ref.arrayLength()); + const int string_length = strnlen(&(*string_start_iterator), _field_ref.arrayLength()); return std::string(string_start_iterator, string_start_iterator + string_length); } diff --git a/ulog_cpp/simple_writer.cpp b/ulog_cpp/simple_writer.cpp index 0651859..9c91fa4 100644 --- a/ulog_cpp/simple_writer.cpp +++ b/ulog_cpp/simple_writer.cpp @@ -5,8 +5,9 @@ #include "simple_writer.hpp" -#ifdef WINDOWS +#ifdef _WIN32 #include +#include // NOLINT #else #include #endif @@ -112,8 +113,8 @@ void SimpleWriter::fsync() { if (_file) { fflush(_file); -#ifdef WINDOWS - FlushFileBuffers(static_cast(_fileno(_file))); +#ifdef _WIN32 + FlushFileBuffers(reinterpret_cast(static_cast(_fileno(_file)))); #else ::fsync(fileno(_file)); #endif From 06de16434db22d56337f352679e7c01f696231c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 19 Aug 2024 13:10:35 +0200 Subject: [PATCH 3/3] messages: return fields by const ref --- ulog_cpp/messages.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ulog_cpp/messages.hpp b/ulog_cpp/messages.hpp index aa471e8..2f5769a 100644 --- a/ulog_cpp/messages.hpp +++ b/ulog_cpp/messages.hpp @@ -586,7 +586,7 @@ class MessageFormat { /** * @return the list of fields, in-order */ - std::vector> fields() const { return _fields_ordered; } + const std::vector>& fields() const { return _fields_ordered; } /** * @return the list of field names, in-order