Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apis/c++/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ ros2-bridge = [
"dep:dora-ros2-bridge-msg-gen",
"dep:rust-format",
"dep:prettyplease",
"dep:serde",
"dep:serde-big-array",
]

Expand All @@ -32,7 +31,8 @@ dora-node-api = { workspace = true }
eyre = "0.6.8"
dora-ros2-bridge = { workspace = true, optional = true }
futures-lite = { version = "2.2" }
serde = { version = "1.0.164", features = ["derive"], optional = true }
serde = { version = "1.0.164", features = ["derive"] }
serde_json = { version = "1.0" }
serde-big-array = { version = "0.5.1", optional = true }
arrow = { workspace = true, features = ["ffi"] }

Expand Down
75 changes: 75 additions & 0 deletions apis/c++/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,81 @@ Instead, use the following functions to read and destructure the event:
- The `data` of inputs is currently of type [`rust::Vec<uint8_t>`](https://cxx.rs/binding/vec.html). Use the provided methods for reading or converting the data.
- **Note:** In the future, we plan to change the data type to the [Apache Arrow](https://arrow.apache.org/) data format to support typed inputs.

### Receiving Arrow Inputs

For Arrow-based inputs, you can use the following functions to receive typed data along with metadata:

- `event_as_arrow_input(event, out_array, out_schema)` - Returns only the Arrow array data (original function)
- `event_as_arrow_input_with_info(event, out_array, out_schema)` - Returns Arrow array data plus input ID and metadata as JSON

**Example using `event_as_arrow_input_with_info`:**

```c++
struct ArrowArray c_array;
struct ArrowSchema c_schema;

// Get Arrow array along with input ID and metadata
auto input_info = event_as_arrow_input_with_info(
std::move(event),
reinterpret_cast<uint8_t*>(&c_array),
reinterpret_cast<uint8_t*>(&c_schema)
);

// Check for errors
if (!input_info.error.empty()) {
std::cerr << "Error: " << input_info.error << std::endl;
return;
}

// Access input ID
std::cout << "Input ID: " << input_info.id << std::endl;

// Access metadata via the provided helper type
auto metadata = std::move(input_info.metadata);
std::cout << "Metadata timestamp: " << metadata->timestamp() << std::endl;

auto keys = metadata->list_keys();
for (std::size_t i = 0; i < keys.size(); i++) {
const std::string key(keys[i]);
try {
switch (metadata->type(key)) {
case MetadataValueType::Float:
std::cout << "Parameter " << key << " (float): "
<< metadata->get_float(key) << std::endl;
break;
case MetadataValueType::Integer:
std::cout << "Parameter " << key << " (int): "
<< metadata->get_int(key) << std::endl;
break;
case MetadataValueType::String:
std::cout << "Parameter " << key << " (string): "
<< std::string(metadata->get_str(key)) << std::endl;
break;
case MetadataValueType::Bool:
std::cout << "Parameter " << key << " (bool): "
<< std::string(metadata->get_json(key)) << std::endl;
break;
default:
std::cout << "Parameter " << key << " has unsupported type" << std::endl;
break;
}
} catch (const std::exception& err) {
std::cout << "Parameter " << key << " unavailable: " << err.what() << std::endl;
}
}

std::cout << "Metadata as JSON: " << std::string(metadata->to_json()) << std::endl;

// Import the Arrow array for processing
auto result = arrow::ImportArray(&c_array, &c_schema);
std::shared_ptr<arrow::Array> input_array = result.ValueOrDie();
```

The metadata JSON contains:
- `timestamp` - Message timestamp with `secs` and `nanos` fields
- `type_info` - Arrow type information
- `parameters` - Custom metadata parameters (key-value pairs)

### Sending Outputs

Nodes can send outputs using the `send_output` output function and the `dora_node.send_output` field.
Expand Down
Loading
Loading