Skip to content

Commit e2224c3

Browse files
genevanmeterGene VanMeter
authored andcommitted
Added protobuf descriptor support
Fixed cargo tests
1 parent debaefd commit e2224c3

File tree

10 files changed

+65
-27
lines changed

10 files changed

+65
-27
lines changed

rustecal-samples/pubsub/person_receive/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ build = "build.rs"
66

77
[dependencies]
88
prost = "0.14"
9+
prost-reflect = { version = "0.16.0", features = ["derive"] }
910
rustecal = { path = "../../../rustecal", features = ["pubsub"] }
1011
rustecal-types-protobuf = { path = "../../../rustecal-types-protobuf" }
1112

1213
[build-dependencies]
1314
prost-build = "0.14"
15+
prost-reflect-build = "0.16.0"
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
fn main() {
2-
prost_build::compile_protos(
3-
&[
4-
"proto/person.proto",
5-
"proto/animal.proto",
6-
"proto/house.proto",
7-
],
8-
&["proto"],
9-
)
10-
.unwrap();
2+
let protos = [
3+
"proto/person.proto",
4+
"proto/animal.proto",
5+
"proto/house.proto",
6+
];
7+
8+
let protos_inc = ["proto"];
9+
10+
prost_build::compile_protos(&protos, &protos_inc).unwrap();
11+
12+
prost_reflect_build::Builder::new()
13+
.descriptor_pool("crate::DESCRIPTOR_POOL")
14+
.compile_protos(&protos, &protos_inc)
15+
.unwrap();
1116
}

rustecal-samples/pubsub/person_receive/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ mod environment {
1212
include!(concat!(env!("OUT_DIR"), "/pb.environment.rs"));
1313
}
1414

15+
use prost_reflect::DescriptorPool;
16+
use std::sync::LazyLock;
17+
18+
static DESCRIPTOR_POOL: LazyLock<DescriptorPool> = LazyLock::new(|| {
19+
DescriptorPool::decode(
20+
include_bytes!(concat!(env!("OUT_DIR"), "/file_descriptor_set.bin")).as_ref(),
21+
)
22+
.unwrap()
23+
});
24+
1525
use people::Person;
1626
impl IsProtobufType for Person {}
1727

rustecal-samples/pubsub/person_send/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ build = "build.rs"
66

77
[dependencies]
88
prost = "0.14"
9+
prost-reflect = { version = "0.16.0", features = ["derive"] }
910
rustecal = { path = "../../../rustecal", features = ["pubsub"] }
1011
rustecal-types-protobuf = { path = "../../../rustecal-types-protobuf" }
1112

1213
[build-dependencies]
1314
prost-build = "0.14"
15+
prost-reflect-build = "0.16.0"
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
fn main() {
2-
prost_build::compile_protos(
3-
&[
4-
"proto/person.proto",
5-
"proto/animal.proto",
6-
"proto/house.proto",
7-
],
8-
&["proto"],
9-
)
10-
.unwrap();
2+
let protos = [
3+
"proto/person.proto",
4+
"proto/animal.proto",
5+
"proto/house.proto",
6+
];
7+
8+
let protos_inc = ["proto"];
9+
10+
prost_build::compile_protos(&protos, &protos_inc).unwrap();
11+
12+
prost_reflect_build::Builder::new()
13+
.descriptor_pool("crate::DESCRIPTOR_POOL")
14+
.compile_protos(&protos, &protos_inc)
15+
.unwrap();
1116
}

rustecal-samples/pubsub/person_send/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ mod environment {
1111
include!(concat!(env!("OUT_DIR"), "/pb.environment.rs"));
1212
}
1313

14+
use prost_reflect::DescriptorPool;
15+
use std::sync::LazyLock;
16+
17+
static DESCRIPTOR_POOL: LazyLock<DescriptorPool> = LazyLock::new(|| {
18+
DescriptorPool::decode(
19+
include_bytes!(concat!(env!("OUT_DIR"), "/file_descriptor_set.bin")).as_ref(),
20+
)
21+
.unwrap()
22+
});
23+
1424
use people::Person;
1525
use rustecal::pubsub::publisher::Timestamp;
1626

rustecal-service/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
//! - `ServiceServer`: host services, handle requests with callbacks.
88
//!
99
//! ## Example
10-
//! ```rust
10+
//! '''rust
1111
//! use rustecal_service::ServiceClient;
1212
//! let client = ServiceClient::new("mirror_service").unwrap();
1313
//! let response = client.call("Hello!".as_bytes(), std::time::Duration::from_millis(500));
14-
//! ```
14+
//! '''
1515
1616
pub mod client;
1717
pub mod client_instance;

rustecal-types-protobuf/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ keywords = ["ecal", "ipc", "pubsub", "message-support", "middleware"]
1212
categories = ["network-programming", "api-bindings"]
1313

1414
[dependencies]
15-
prost = "0.14"
15+
prost = "0.14"
16+
prost-reflect = { version = "0.16.0", features = ["derive"] }
1617
rustecal-core = { version = "0.1", path = "../rustecal-core" }
1718
rustecal-pubsub = { version = "0.1", path = "../rustecal-pubsub" }

rustecal-types-protobuf/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! Provides support for Protobuf message serialization with rustecal.
44
55
use prost::Message;
6+
use prost_reflect::ReflectMessage;
67
use rustecal_core::types::DataTypeInfo;
78
use rustecal_pubsub::typed_publisher::PublisherMessage;
89
use rustecal_pubsub::typed_subscriber::SubscriberMessage;
@@ -26,7 +27,7 @@ pub struct ProtobufMessage<T> {
2627

2728
impl<T> SubscriberMessage<'_> for ProtobufMessage<T>
2829
where
29-
T: Message + Default + IsProtobufType,
30+
T: Message + Default + IsProtobufType + ReflectMessage,
3031
{
3132
/// Returns metadata used by eCAL to describe the Protobuf type.
3233
///
@@ -35,10 +36,12 @@ where
3536
/// - the Rust type name
3637
/// - an optional descriptor (currently empty)
3738
fn datatype() -> DataTypeInfo {
39+
let default_instance = T::default();
40+
3841
DataTypeInfo {
3942
encoding: "proto".to_string(),
40-
type_name: std::any::type_name::<T>().to_string(),
41-
descriptor: vec![], // descriptor injection planned
43+
type_name: default_instance.descriptor().full_name().to_string(),
44+
descriptor: default_instance.descriptor().parent_pool().encode_to_vec(), // descriptor injection planned
4245
}
4346
}
4447

@@ -56,7 +59,7 @@ where
5659

5760
impl<T> PublisherMessage for ProtobufMessage<T>
5861
where
59-
T: Message + Default + IsProtobufType,
62+
T: Message + Default + IsProtobufType + ReflectMessage,
6063
{
6164
/// Returns the same datatype information as [`SubscriberMessage`] implementation.
6265
fn datatype() -> DataTypeInfo {

rustecal/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
//! - `service`: Synchronous RPC communication.
1010
//!
1111
//! ## Example
12-
//! ```rust
12+
//! '''rust
1313
//! use rustecal::{Ecal, TypedPublisher};
1414
//! use rustecal_types_string::StringMessage;
1515
//!
1616
//! Ecal::initialize(Some("example node"), EcalComponents::DEFAULT, None).unwrap();
1717
//! let pub_ = TypedPublisher::<StringMessage>::new("hello topic").unwrap();
1818
//! pub_.send(&StringMessage{data: "Hello!".into()}, Timestamp::Auto);
19-
//! ```
19+
//! '''
2020
//!
2121
2222
// —————————————————————————————————————————————————————————————————————————————

0 commit comments

Comments
 (0)