Comments (6)
I'm not an expert of C++, but maybe try adding .data()
at the end:
std::memcpy(PointCloud2.data.data(), output_data, output_data_len);
From memory alone, I think that PointCloud2.data
is a standard vector in C++
https://chat.openai.com/c/c42af36d-9385-4db5-a168-c1337d570335
p.s: note that you can use ```c++ for syntax highlighting
from dora.
See https://cxx.rs/binding/vec.html for the type definition of rust::Vec<T>
. While it's similar to a std::vector
, it's a different type without any direction conversion. Unfortunately, I don't see any more efficient way to push multiple values either.
std::memcpy(PointCloud2.data.data(), output_data, output_data_len);
This is unsafe and will lead to undefined behavior if output_data_len
is greater than PointCloud2.data.size()
.
A possible solution could be to generate two versions of each message type: one based on Rust types and one based on C++ types. The version based on C++ types would then contain normal std::vector
fields instead of rust::Vec
. Subscribe methods would only support the version based on Rust-types, but publish methods could support both types. The drawback is that it duplicates all message types, which could be confusing. What do you think about this approach @ShoreFlower?
from dora.
from dora.
To avoid the boilerplate of the for
loop, you should be able to use back_inserter
together with std::copy
.
Doing a pointer copy would require a public set_len
method, which is being discussed upstream. However, apparently such a function isn't even available for the standard C++ vector
type.
If you're concerned about efficiency, you should try doing a benchmark with link-time optimization enabled. I can imagine that the compiler/linker optimizes the for
loop and push_back
calls to some quite efficient code.
from dora.
To make the push_back
operation cheap you can call reserve
with the required capacity beforehand. Then no reallocation is required anymore.
from dora.
Thank you for your answer, for having used std::copy
can solve the data problem.
std::copy(output_data + 16, output_data + output_data_len, std::back_inserter(PointCloud2.data));
from dora.
Related Issues (20)
- ROS2 messages not work between python and C++ dora node HOT 2
- ros2 action and parameter example needed HOT 1
- Add fix for cmake in cmake-dateflow example HOT 1
- Create a `dora-timer` tool nodes HOT 1
- Nodes with no inputs has empty events stream HOT 3
- Error when a node receives two data streams HOT 4
- Make dora node API minor versions compatible with one another. HOT 5
- Make dora cli connect to remote coordinator HOT 3
- Tracking issue for using `zenoh` in dora HOT 1
- Using thread in on_event becomes slower HOT 3
- dora node packet loss HOT 16
- Error when using c_node HOT 9
- Dependency Dashboard
- Action Required: Fix Renovate Configuration
- Hot reload does not work with complex configuration vim HOT 2
- Next steps for distributed deployments HOT 9
- ros2-bridge action implementation
- Thread-safety of C node API
- Some issues we are currently facing with using dora-rs. HOT 1
- Python API automatic `__str__` derivation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dora.