Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Windows support #11

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ulog_cpp/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion ulog_cpp/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ class MessageFormat {
/**
* @return the list of fields, in-order
*/
std::vector<std::shared_ptr<Field>> fields() const { return _fields_ordered; }
const std::vector<std::shared_ptr<Field>>& fields() const { return _fields_ordered; }

/**
* @return the list of field names, in-order
Expand Down
9 changes: 9 additions & 0 deletions ulog_cpp/simple_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

#include "simple_writer.hpp"

#ifdef _WIN32
#include <fileapi.h>
#include <windows.h> // NOLINT
#else
#include <unistd.h>
#endif

namespace ulog_cpp {

Expand Down Expand Up @@ -108,7 +113,11 @@ void SimpleWriter::fsync()
{
if (_file) {
fflush(_file);
#ifdef _WIN32
FlushFileBuffers(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(_fileno(_file))));
#else
::fsync(fileno(_file));
#endif
}
}
uint16_t SimpleWriter::writeAddLoggedMessage(const std::string& message_format_name,
Expand Down
Loading