diff --git a/Cargo.toml b/Cargo.toml index 64c5268..9287bd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,7 @@ futures-core = "0.3.21" futures-util = "0.3.21" prost = "0.10.4" prost-derive = "0.10.1" +serde = { version = "1.0.138", features = ["derive"] } thiserror = "1.0.31" tokio = { version = "1.18.2", features = ["parking_lot"] } tonic = { version = "0.7.2", features = ["codegen"] } diff --git a/build.rs b/build.rs index 5c56668..76f6381 100644 --- a/build.rs +++ b/build.rs @@ -15,9 +15,12 @@ // fn main() -> Result<(), Box> { - tonic_build::configure().build_server(false).compile( - &["./skywalking-data-collect-protocol/language-agent/Tracing.proto"], - &["./skywalking-data-collect-protocol"], - )?; + tonic_build::configure() + .build_server(false) + .type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]") + .compile( + &["./skywalking-data-collect-protocol/language-agent/Tracing.proto"], + &["./skywalking-data-collect-protocol"], + )?; Ok(()) } diff --git a/src/skywalking_proto/v3/mod.rs b/src/skywalking_proto/v3/mod.rs index cd8302a..e535cbf 100644 --- a/src/skywalking_proto/v3/mod.rs +++ b/src/skywalking_proto/v3/mod.rs @@ -49,3 +49,20 @@ impl SpanObject { }); } } + +#[cfg(test)] +mod tests { + use super::*; + + trait AssertSerialize: serde::Serialize {} + + impl AssertSerialize for SegmentObject {} + + impl AssertSerialize for SpanObject {} + + trait AssertDeserialize<'de>: serde::Deserialize<'de> {} + + impl AssertDeserialize<'_> for SegmentObject {} + + impl AssertDeserialize<'_> for SpanObject {} +}