Skip to content

Commit

Permalink
Added google.protobuf.Empty which serializes to {}.
Browse files Browse the repository at this point in the history
  • Loading branch information
fdeantoni committed Feb 18, 2023
1 parent 0e5a8d7 commit 44d400d
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prost-wkt"
version = "0.4.0"
version = "0.4.1"
authors = ["fdeantoni <[email protected]>"]
license = "Apache-2.0"
repository = "https://github.com/fdeantoni/prost-wkt"
Expand All @@ -13,7 +13,7 @@ edition = "2021"
members = [ "wkt-build", "wkt-types", "example" ]

[dependencies]
prost = "0.11.5"
prost = "0.11.6"
inventory = "0.3.0"
serde = "1.0"
serde_json = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "prost-wkt-example"
version = "0.4.0"
version = "0.4.1"
authors = ["fdeantoni <[email protected]>"]
edition = "2021"

[dependencies]
prost = "0.11.5"
prost = "0.11.6"
prost-wkt = { path = ".." }
prost-wkt-types = { path = "../wkt-types" }
serde = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions wkt-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prost-wkt-build"
version = "0.4.0"
version = "0.4.1"
authors = ["fdeantoni <[email protected]>"]
license = "Apache-2.0"
repository = "https://github.com/fdeantoni/prost-wkt"
Expand All @@ -10,7 +10,7 @@ documentation = "https://docs.rs/prost-wkt-build"
edition = "2021"

[dependencies]
prost = "0.11.5"
prost = "0.11.6"
prost-types = "0.11.5"
prost-build = "0.11.5"
quote = "1.0"
Expand Down
10 changes: 5 additions & 5 deletions wkt-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prost-wkt-types"
version = "0.4.0"
version = "0.4.1"
authors = ["fdeantoni <[email protected]>"]
license = "Apache-2.0"
repository = "https://github.com/fdeantoni/prost-wkt"
Expand All @@ -19,16 +19,16 @@ default = ["std"]
std = []

[dependencies]
prost-wkt = { version = "0.4.0", path = ".." }
prost = "0.11.5"
prost-wkt = { version = "0.4.1", path = ".." }
prost = "0.11.6"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
chrono = { version = "0.4", default-features = false, features = ["serde"] }

[build-dependencies]
prost = "0.11.5"
prost = "0.11.6"
prost-types = "0.11.5"
prost-build = "0.11.5"
prost-wkt-build = { version = "0.4.0", path = "../wkt-build" }
prost-wkt-build = { version = "0.4.1", path = "../wkt-build" }
regex = "1"
2 changes: 2 additions & 0 deletions wkt-types/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn main() {
build(&dir, "pbtime");
build(&dir, "pbstruct");
build(&dir, "pbany");
build(&dir, "pbempty");
}

fn build(dir: &Path, proto: &str) {
Expand All @@ -30,6 +31,7 @@ fn build(dir: &Path, proto: &str) {
.type_attribute("google.protobuf.Struct","#[derive(serde_derive::Serialize, serde_derive::Deserialize)] #[serde(default, rename_all=\"camelCase\")]")
.type_attribute("google.protobuf.ListValue","#[derive(serde_derive::Serialize, serde_derive::Deserialize)] #[serde(default, rename_all=\"camelCase\")]")
.type_attribute("google.protobuf.Duration","#[derive(serde_derive::Serialize, serde_derive::Deserialize)] #[serde(default, rename_all=\"camelCase\")]")
.type_attribute("google.protobuf.Empty","#[derive(serde_derive::Serialize, serde_derive::Deserialize)]")
.file_descriptor_set_path(&descriptor_file)
.out_dir(&out)
.compile_protos(
Expand Down
5 changes: 5 additions & 0 deletions wkt-types/proto/pbempty.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
syntax = "proto3";

import "google/protobuf/empty.proto";

package empty;
3 changes: 3 additions & 0 deletions wkt-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ pub use crate::pbstruct::*;
mod pbany;
pub use crate::pbany::*;

mod pbempty;
pub use crate::pbempty::*;

pub use prost_wkt::MessageSerde;
36 changes: 36 additions & 0 deletions wkt-types/src/pbempty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
include!(concat!(env!("OUT_DIR"), "/pbempty/google.protobuf.rs"));

const EMPTY: Empty = Empty {};

impl From<()> for Empty {
fn from(_value: ()) -> Self {
EMPTY
}
}

#[cfg(test)]
mod tests {

use crate::pbempty::*;

#[test]
fn serialize_empty() {
let msg = EMPTY;
println!(
"Serialized to string: {}",
serde_json::to_string_pretty(&msg).unwrap()
);
}

#[test]
fn deserialize_empty() {
let msg: Empty = serde_json::from_str("{}").expect("Could not deserialize `{}` to an Empty struct!");
assert_eq!(msg, EMPTY);
}

#[test]
fn convert_unit() {
let msg: Empty = ().into();
assert_eq!(msg, Empty {});
}
}

0 comments on commit 44d400d

Please sign in to comment.