Skip to content

Commit c5984fd

Browse files
committed
example: upgrade protobuf from 2.x to 3.x
Upgrade protobuf in example. Signed-off-by: Tim Zhang <tim@hyper.sh>
1 parent ab5380a commit c5984fd

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
lines changed

example/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ homepage = "https://github.com/alipay/ttrpc-rust"
1111
description = "An example of ttrpc."
1212

1313
[dev-dependencies]
14-
protobuf = "2.8.0"
14+
protobuf = "3.1.0"
1515
bytes = "0.4.11"
1616
libc = "0.2.79"
1717
byteorder = "1.3.2"

example/async-server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ impl agent_ttrpc::AgentService for AgentService {
6666
_ctx: &::ttrpc::r#async::TtrpcContext,
6767
_req: agent::ListInterfacesRequest,
6868
) -> ::ttrpc::Result<agent::Interfaces> {
69-
let mut rp = protobuf::RepeatedField::new();
69+
let mut rp = Vec::new();
7070

7171
let mut i = types::Interface::new();
72-
i.set_name("first".to_string());
72+
i.name = "first".to_string();
7373
rp.push(i);
7474
let mut i = types::Interface::new();
75-
i.set_name("second".to_string());
75+
i.name = "second".to_string();
7676
rp.push(i);
7777

7878
let mut i = agent::Interfaces::new();
79-
i.set_Interfaces(rp);
79+
i.Interfaces = rp;
8080

8181
Ok(i)
8282
}

example/build.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
// SPDX-License-Identifier: Apache-2.0
44
//
55

6-
use std::fs::File;
7-
use std::io::{Read, Write};
8-
use ttrpc_codegen::Codegen;
9-
use ttrpc_codegen::Customize;
6+
use std::{
7+
fs::File,
8+
io::{Read, Write},
9+
};
10+
use ttrpc_codegen::{Codegen, Customize, ProtobufCustomize};
1011

1112
fn main() {
1213
let mut protos = vec![
14+
"protocols/protos/github.com/gogo/protobuf/gogoproto/gogo.proto",
1315
"protocols/protos/github.com/kata-containers/agent/pkg/types/types.proto",
1416
"protocols/protos/agent.proto",
1517
"protocols/protos/health.proto",
1618
"protocols/protos/google/protobuf/empty.proto",
1719
"protocols/protos/oci.proto",
1820
];
1921

22+
let protobuf_customized = ProtobufCustomize::default().gen_mod_rs(false);
23+
2024
Codegen::new()
2125
.out_dir("protocols/sync")
2226
.inputs(&protos)
@@ -25,6 +29,7 @@ fn main() {
2529
.customize(Customize {
2630
..Default::default()
2731
})
32+
.rust_protobuf_customize(protobuf_customized.clone())
2833
.run()
2934
.expect("Gen sync code failed.");
3035

@@ -40,6 +45,7 @@ fn main() {
4045
async_all: true,
4146
..Default::default()
4247
})
48+
.rust_protobuf_customize(protobuf_customized.clone())
4349
.run()
4450
.expect("Gen async code failed.");
4551

example/protocols/asynchronous/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
pub mod agent;
77
pub mod agent_ttrpc;
88
pub mod empty;
9+
mod gogo;
910
pub mod health;
1011
pub mod health_ttrpc;
1112
mod oci;
12-
pub mod types;
1313
pub mod streaming;
1414
pub mod streaming_ttrpc;
15+
pub mod types;

example/protocols/protos/health.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ option (gogoproto.benchgen_all) = true;
1717

1818
message CheckRequest {
1919
string service = 1;
20+
optional string option_val = 2;
2021
}
2122

2223
message HealthCheckResponse {

example/protocols/sync/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
pub mod agent;
77
pub mod agent_ttrpc;
88
pub mod empty;
9+
mod gogo;
910
pub mod health;
1011
pub mod health_ttrpc;
1112
mod oci;

example/server.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,19 @@ impl agent_ttrpc::AgentService for AgentService {
6363
_ctx: &::ttrpc::TtrpcContext,
6464
_req: agent::ListInterfacesRequest,
6565
) -> ::ttrpc::Result<agent::Interfaces> {
66-
let mut rp = protobuf::RepeatedField::new();
67-
68-
let mut i = types::Interface::new();
69-
i.set_name("first".to_string());
70-
rp.push(i);
71-
let mut i = types::Interface::new();
72-
i.set_name("second".to_string());
73-
rp.push(i);
74-
75-
let mut i = agent::Interfaces::new();
76-
i.set_Interfaces(rp);
77-
78-
Ok(i)
66+
Ok(agent::Interfaces {
67+
Interfaces: vec![
68+
types::Interface {
69+
name: "first".to_string(),
70+
..Default::default()
71+
},
72+
types::Interface {
73+
name: "second".to_string(),
74+
..Default::default()
75+
},
76+
],
77+
..Default::default()
78+
})
7979
}
8080
}
8181

0 commit comments

Comments
 (0)