Skip to content
This repository was archived by the owner on Jun 4, 2023. It is now read-only.

Commit c3e4d6d

Browse files
committed
ttrpc-codegen: upgrade protobuf from 2.x to 3.x
Upgrade ttrpc-codegen's dep protobuf from 2.x to 3.x Signed-off-by: Tim Zhang <[email protected]>
1 parent fbe8cb9 commit c3e4d6d

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

ttrpc-codegen/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ readme = "README.md"
1313

1414

1515
[dependencies]
16-
protobuf = { version = "2.14.0" }
17-
protobuf-codegen-pure = "2.14.0"
18-
protobuf-codegen = "2.14.0"
19-
ttrpc-compiler = "0.6.0"
16+
protobuf-support = "3.1.0"
17+
protobuf = { version = "2.27.1" }
18+
protobuf-codegen = "3.1.0"
19+
ttrpc-compiler = {path = "../compiler"}

ttrpc-codegen/src/lib.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
//! API to generate .rs files for ttrpc from protobuf
22
//!
33
//!
4-
//!```
5-
//!use ttrpc_codegen::Codegen;
6-
//!use ttrpc_codegen::Customize;
4+
//!```no_run
5+
//!use ttrpc_codegen::{Customize, Codegen, ProtobufCustomize};
76
//!# use std::path::Path;
87
//!
98
//!fn main() {
109
//!# let protos: Vec<&Path> = vec![];
10+
//! let protobuf_customized = ProtobufCustomize::default().gen_mod_rs(false);
11+
//!
1112
//! Codegen::new()
12-
//! .out_dir("protocols/sync")
13+
//! .out_dir("protocols/asynchronous")
1314
//! .inputs(&protos)
1415
//! .include("protocols/protos")
1516
//! .rust_protobuf()
1617
//! .customize(Customize {
18+
//! async_all: true,
1719
//! ..Default::default()
1820
//! })
21+
//! .rust_protobuf_customize(protobuf_customized.clone())
1922
//! .run()
20-
//! .expect("Gen code failed.");
21-
//!}
22-
//!
23-
//!```
23+
//! .expect("Gen async code failed.");
24+
//! }
2425
2526
pub use protobuf_codegen::Customize as ProtobufCustomize;
2627
use std::collections::HashMap;
@@ -121,7 +122,8 @@ impl Codegen {
121122
let p = parse_and_typecheck(&includes, &inputs)?;
122123

123124
if self.rust_protobuf {
124-
protobuf_codegen_pure::Codegen::new()
125+
protobuf_codegen::Codegen::new()
126+
.pure()
125127
.out_dir(&self.out_dir)
126128
.inputs(&self.inputs)
127129
.includes(&self.includes)

ttrpc-codegen/src/model.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use crate::parser::{Loc, Parser, ParserErrorWithLocation};
77
use crate::str_lit::StrLit;
8-
use protobuf_codegen::float;
8+
use protobuf_support::lexer::float;
99

1010
/// Protobox syntax
1111
#[derive(Debug, Clone, Copy, Eq, PartialEq)]

ttrpc-codegen/src/parser.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::str;
55

66
use crate::model::*;
77
use crate::str_lit::*;
8-
use protobuf_codegen::float;
8+
use protobuf_support::lexer::float;
99

1010
const FIRST_LINE: u32 = 1;
1111
const FIRST_COL: u32 = 1;
@@ -735,11 +735,15 @@ impl MessageBodyParseMode {
735735
| MessageBodyParseMode::ExtendProto3 => true,
736736
MessageBodyParseMode::Oneof => false,
737737
},
738-
Rule::Optional | Rule::Required => match *self {
738+
Rule::Optional => match *self {
739739
MessageBodyParseMode::MessageProto2 | MessageBodyParseMode::ExtendProto2 => true,
740-
MessageBodyParseMode::MessageProto3
741-
| MessageBodyParseMode::ExtendProto3
742-
| MessageBodyParseMode::Oneof => false,
740+
MessageBodyParseMode::MessageProto3 | MessageBodyParseMode::ExtendProto3 => true,
741+
MessageBodyParseMode::Oneof => false,
742+
},
743+
Rule::Required => match *self {
744+
MessageBodyParseMode::MessageProto2 | MessageBodyParseMode::ExtendProto2 => true,
745+
MessageBodyParseMode::MessageProto3 | MessageBodyParseMode::ExtendProto3 => false,
746+
MessageBodyParseMode::Oneof => false,
743747
},
744748
}
745749
}
@@ -1974,7 +1978,7 @@ mod test {
19741978
let mess = parse(msg, |p| p.next_field(MessageBodyParseMode::MessageProto2));
19751979
assert_eq!("f", mess.name);
19761980
assert_eq!("default", mess.options[0].name);
1977-
assert_eq!("10.0", mess.options[0].value.format());
1981+
assert_eq!("10", mess.options[0].value.format());
19781982
}
19791983

19801984
#[test]

0 commit comments

Comments
 (0)