Skip to content

Commit ea27b80

Browse files
committed
Add serde feature flag to prost-types
Adds "serde_deserialize", "serde_serialize" and "serde" flags to prost-types. This will allow users to enable serde support to the well known types. closes #852
1 parent 846c452 commit ea27b80

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

prost-types/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ doctest = false
1616
default = ["std"]
1717
std = ["prost/std"]
1818
arbitrary = ["dep:arbitrary"]
19+
serde = ["dep:serde"]
1920

2021
[dependencies]
2122
prost = { version = "0.13.5", path = "../prost", default-features = false, features = ["prost-derive"] }
2223
arbitrary = { version = "1.4", features = ["derive"], optional = true }
2324
chrono = { version = "0.4.34", default-features = false, optional = true }
25+
serde = { version = "1.0.218", default-features = false, optional = true, features = ["derive"] }
2426

2527
[dev-dependencies]
2628
proptest = "1"

prost-types/src/compiler.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// This file is @generated by prost-build.
22
/// The version number of protocol compiler.
33
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
4+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
45
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
56
pub struct Version {
67
#[prost(int32, optional, tag = "1")]
@@ -16,6 +17,7 @@ pub struct Version {
1617
}
1718
/// An encoded CodeGeneratorRequest is written to the plugin's stdin.
1819
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
20+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1921
#[derive(Clone, PartialEq, ::prost::Message)]
2022
pub struct CodeGeneratorRequest {
2123
/// The .proto files that were explicitly listed on the command-line. The
@@ -48,6 +50,7 @@ pub struct CodeGeneratorRequest {
4850
}
4951
/// The plugin writes an encoded CodeGeneratorResponse to stdout.
5052
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
53+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
5154
#[derive(Clone, PartialEq, ::prost::Message)]
5255
pub struct CodeGeneratorResponse {
5356
/// Error message. If non-empty, code generation failed. The plugin process
@@ -71,6 +74,7 @@ pub struct CodeGeneratorResponse {
7174
pub mod code_generator_response {
7275
/// Represents a single generated file.
7376
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
77+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
7478
#[derive(Clone, PartialEq, ::prost::Message)]
7579
pub struct File {
7680
/// The file name, relative to the output directory. The name must not
@@ -136,6 +140,7 @@ pub mod code_generator_response {
136140
}
137141
/// Sync with code_generator.h.
138142
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
143+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
139144
#[derive(
140145
Clone,
141146
Copy,

prost-types/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
//! - `std`: Enable integration with standard library. Disable this feature for `no_std` support. This feature is enabled by default.
3838
//! - `arbitrary`: Enable integration with crate `arbitrary`. All types on this crate will implement `trait Arbitrary`.
3939
//! - `chrono`: Enable integration with crate `chrono`. Time related types implement conversions to/from their `chrono` equivalent.
40+
//! - `serde`: Enable integration with crate `serde`. All types on this crate will implement `trait Serialize` and `trait Deserialize`.
4041
//!
4142
//! [1]: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf
4243

0 commit comments

Comments
 (0)