Examples
Learn HDDS through 193 practical examples covering every aspect of DDS. All examples are available in multiple languages: Rust, Python, C++, and C.
SDK Samples
The complete samples collection is available in the HDDS repository:
git clone https://git.hdds.io/hdds/hdds.git
cd hdds/sdk/samples
Sample Categories
| Category | Samples | Description |
|---|---|---|
| 01_basics | 21 | Hello world, pub/sub fundamentals |
| 02_qos | 36 | All 22 QoS policies with examples |
| 03_types | 62 | Every IDL type: structs, enums, sequences, maps, unions |
| 04_discovery | 16 | SPDP/SEDP, static peers, discovery tuning |
| 05_security | 17 | Authentication, encryption, access control |
| 06_performance | 16 | Latency tuning, throughput optimization, benchmarks |
| 07_advanced | 16 | Waitsets, listeners, content filters, instances |
| 08_interop | 3 | Cross-vendor communication |
| 09_ros2 | 3 | ROS2 rmw_hdds integration |
| 10_usecases | 3 | Complete real-world scenarios |
Basics
Path: sdk/samples/01_basics/
| Example | Languages | Description |
|---|---|---|
| hello_world | Rust, Python, C++, C | Minimal pub/sub |
| pubsub | Rust, Python, C++, C | Basic publisher and subscriber |
| multiple_topics | Rust, Python | Multiple topics in one participant |
| participant_config | Rust, Python | Participant configuration options |
| graceful_shutdown | Rust | Clean shutdown with signal handling |
# Run hello world
cd 01_basics/rust && cargo run --bin hello_world
cd 01_basics/python && python hello_world.py
QoS Policies
Path: sdk/samples/02_qos/
Examples for all 22 DDS QoS policies:
| Sample | Description | Key QoS |
|---|---|---|
| reliable_delivery | Guaranteed delivery with NACK retransmission | RELIABLE |
| best_effort | Fire-and-forget, lowest latency | BEST_EFFORT |
| transient_local | Late-joiner support with historical data | TRANSIENT_LOCAL |
| deadline_monitor | Monitor data update rate violations | DEADLINE |
| liveliness_auto | System heartbeats for presence detection | LIVELINESS(AUTO) |
| liveliness_manual | App-level heartbeat assertion | LIVELINESS(MANUAL) |
| partition_filter | Logical data filtering by namespace | PARTITION |
| ownership_exclusive | Strength-based writer arbitration | OWNERSHIP(EXCLUSIVE) |
| history_keep_last | Retain N most recent samples | HISTORY(KEEP_LAST) |
QoS Quick Reference
| QoS Policy | Options | Use Case |
|---|---|---|
| Reliability | RELIABLE / BEST_EFFORT | Guaranteed delivery vs low latency |
| Durability | VOLATILE / TRANSIENT_LOCAL | Late-joiner data access |
| History | KEEP_LAST(N) / KEEP_ALL | Sample retention |
| Deadline | Period duration | Monitor update rate |
| Liveliness | AUTOMATIC / MANUAL_BY_* | Presence detection |
| Ownership | SHARED / EXCLUSIVE | Writer arbitration |
| Partition | String patterns | Logical separation |
# Run reliability example
cd 02_qos/rust && cargo run --bin reliability
# Deadline monitoring
./deadline_monitor # Subscriber
./deadline_monitor pub # Publisher (meets deadlines)
./deadline_monitor slow # Publisher (misses deadlines)
# Partition filtering
./partition_filter sub A # Subscriber in partition "A"
./partition_filter pub A # Publisher in partition "A" (matches)
./partition_filter pub B # Publisher in partition "B" (no match)
IDL Types
Path: sdk/samples/03_types/
Every IDL type supported by hdds_gen:
| Example | Languages | Types |
|---|---|---|
| primitives | Rust, Python, C++ | int8, uint32, float, double, bool |
| strings | Rust, Python | string, bounded string<N> |
| sequences | Rust, Python | sequence<T>, bounded sequence<T, N> |
| arrays | Rust, Python | T[N], multidimensional |
| enums | Rust, Python | enum, @bit_bound |
| structs | Rust, Python | struct, nested structs |
| unions | Rust, Python | union with discriminator |
| maps | Rust, Python | map<K, V> |
| optional | Rust, Python | @optional fields |
| bitsets_bitmasks | Rust, Python | bitset, bitmask |
# Run sequences example
cd 03_types/rust && cargo run --bin sequences
Discovery
Path: sdk/samples/04_discovery/
| Sample | Description |
|---|---|
| simple_discovery | Automatic participant discovery using SPDP multicast |
| static_peers | Manual peer configuration for non-multicast networks |
| discovery_listeners | Callbacks for discovery events (match/unmatch) |
| partitions | Logical data separation with partition QoS |
Partition Matching
Partitions provide logical separation within a domain:
Partition A ────┬──── Partition B
│
Topic "Data" │ Topic "Data"
Writer ─────────┼──── Reader (NO MATCH - different partitions)
│
│
Partition A ────┴──── Partition A
Topic "Data" Topic "Data"
Writer ────────────── Reader (MATCH - same partition)
Wildcard matching: * matches any, Sensor* matches SensorA, SensorB, etc.
Network Requirements
| Sample | Multicast | Unicast | TCP |
|---|---|---|---|
| simple_discovery | Required | Optional | No |
| static_peers | Not used | Required | Optional |
| discovery_listeners | Required | Optional | No |
| partitions | Required | Optional | No |
Security
Path: sdk/samples/05_security/
DDS Security v1.1 examples:
| Sample | Description |
|---|---|
| authentication | PKI-based participant authentication with X.509 certificates |
| access_control | Governance and permissions for topic-level access control |
| encryption | Data encryption (AES-GCM) and message authentication (GMAC) |
| secure_discovery | Authenticated SPDP/SEDP discovery protocol |
Security Architecture
┌─────────────────────────────────────────────────────────────┐
│ Application Layer │
├─────────────────────────────────────────────────────────────┤
│ DDS Layer │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ DataWriter │ │ DataReader │ │ Discovery │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
├─────────┴────────────────┴────────────────┴─────────────────┤
│ Security Plugins │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │Authentication│ │Access Control│ │Cryptography │ │
│ │ Plugin │ │ Plugin │ │ Plugin │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Transport Layer │
│ (UDP/TCP with TLS optional) │
└─────────────────────────────────────────────────────────────┘
Protection Levels
| Level | Confidentiality | Integrity | Overhead |
|---|---|---|---|
| NONE | No | No | 0 bytes |
| SIGN (GMAC) | No | Yes | 16 bytes |
| ENCRYPT (GCM) | Yes | Yes | 16 bytes |
| SIGN+ENCRYPT | Yes | Yes | 32 bytes |
Performance
Path: sdk/samples/06_performance/
| Sample | Description |
|---|---|
| latency | Ping-pong latency measurement with histograms |
| throughput | Maximum messages/sec and MB/sec benchmarks |
| batching | Message batching for improved throughput |
| zero_copy | Shared memory for eliminating data copies |
Performance Metrics
| Metric | Small (64B) | Medium (1KB) | Large (64KB) |
|---|---|---|---|
| Latency | ~50 us | ~75 us | ~200 us |
| Throughput | 1M msg/s | 500K msg/s | 50K msg/s |
| Bandwidth | 64 MB/s | 500 MB/s | 3.2 GB/s |
Batching Efficiency
| Configuration | Packets | Efficiency |
|---|---|---|
| No batching | 10,000 | 1.0x |
| Batch 1KB | 640 | 15.6x |
| Batch 8KB | 80 | 125x |
| Batch 64KB | 10 | 1000x |
Tuning Tips
For low latency:
- Reduce/disable batching
- Pin threads to CPU cores
- Use UDP transport
- Set real-time priority
For high throughput:
- Enable batching (8KB-64KB)
- Use zero-copy for large payloads
- Increase history depth
- Tune socket buffers
Advanced
Path: sdk/samples/07_advanced/
| Sample | Description |
|---|---|
| content_filter | SQL-like content filtering for efficient data subscription |
| request_reply | RPC-style communication patterns over DDS |
| waitsets | Condition-based event handling and multiplexing |
| dynamic_data | Runtime type manipulation and introspection |
WaitSet Architecture
┌─────────────────────────────────────────┐
│ WaitSet │
│ ┌───────────┐ ┌───────────┐ │
│ │ ReadCond │ │ StatusCond│ │
│ │ (Topic A) │ │ (Reader) │ │
│ └───────────┘ └───────────┘ │
│ ┌───────────┐ ┌───────────┐ │
│ │ GuardCond │ │ ReadCond │ │
│ │ (Shutdown)│ │ (Topic B) │ │
│ └───────────┘ └───────────┘ │
└─────────────────────────────────────────┘
│
▼
wait(timeout)
│
▼
Active Conditions List
Condition Types
| Type | Trigger | Use Case |
|---|---|---|
ReadCondition | Data available | Data reception |
StatusCondition | Entity status changed | Liveliness, matches |
GuardCondition | Application signal | Shutdown, inter-thread |
QueryCondition | Filtered data available | Content-filtered reads |
Content Filter Expressions
temperature > 30.0 -- Comparison
location = 'ServerRoom' -- Equality
sensor_id BETWEEN 1 AND 10 -- Range
humidity > %0 -- Parameter reference
location LIKE 'Building%' -- Pattern matching
temp > 25 AND hum > 60 -- Logical operators
Interoperability
Path: sdk/samples/08_interop/
| Example | Description |
|---|---|
| hdds_to_fastdds | HDDS publisher → FastDDS subscriber |
| hdds_to_rti | HDDS ↔ RTI Connext |
| hdds_to_cyclone | HDDS ↔ CycloneDDS |
ROS2 Integration
Path: sdk/samples/09_ros2/
| Example | Description |
|---|---|
| rmw_hdds_talker | ROS2 publisher with rmw_hdds |
| rmw_hdds_listener | ROS2 subscriber with rmw_hdds |
| mixed_dds_ros2 | Native HDDS + ROS2 nodes |
Real-World Use Cases
Path: sdk/samples/10_usecases/
| Example | Description |
|---|---|
| autonomous_vehicle | LiDAR, camera, control topics |
| industrial_iot | Sensor mesh with edge gateway |
| robotics_swarm | Multi-robot coordination |
Building All Samples
cd sdk/samples
# Build all Rust samples
./build.sh rust
# Build all C++ samples
./build.sh cpp
# Build all
make all
Contributing Examples
Want to add an example? See the contribution guide.