Skip to content

Commit a6671be

Browse files
BusyJayhicqu
authored andcommitted
Use the old way to read enum (#75)
1 parent 01424b8 commit a6671be

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ categories = ["algorithms", "database-implementations"]
1313

1414
[dependencies]
1515
log = "0.4.1"
16-
protobuf = "2.0"
16+
protobuf = "~2.0.0"
1717
quick-error = "1.2.1"
1818
rand = "0.4"
1919
fxhash = "0.2.1"

generate-proto.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
protoc proto/eraftpb.proto --rust_out=src/
3+
# TODO: remove this once stepancheg/rust-protobuf#233 is resolved.
4+
python <<EOF
5+
import re
6+
with open("src/eraftpb.rs") as reader:
7+
src = reader.read()
8+
9+
res = re.sub('::protobuf::rt::read_proto3_enum_with_unknown_fields_into\(([^,]+), ([^,]+), &mut ([^,]+), [^\)]+\)\?', 'if \\\\1 == ::protobuf::wire_format::WireTypeVarint {\\\\3 = \\\\2.read_enum()?;} else { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); }', src)
10+
11+
with open("src/eraftpb.rs", "w") as writer:
12+
writer.write(res)
13+
EOF

src/eraftpb.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file is generated by rust-protobuf 1.6.0. Do not edit
1+
// This file is generated by rust-protobuf 2.0.2. Do not edit
22
// @generated
33

44
// https://github.com/Manishearth/rust-clippy/issues/702
@@ -163,7 +163,7 @@ impl ::protobuf::Message for Entry {
163163
let (field_number, wire_type) = is.read_tag_unpack()?;
164164
match field_number {
165165
1 => {
166-
::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.entry_type, 1, &mut self.unknown_fields)?
166+
if wire_type == ::protobuf::wire_format::WireTypeVarint {self.entry_type = is.read_enum()?;} else { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); }
167167
},
168168
2 => {
169169
if wire_type != ::protobuf::wire_format::WireTypeVarint {
@@ -1095,7 +1095,7 @@ impl ::protobuf::Message for Message {
10951095
let (field_number, wire_type) = is.read_tag_unpack()?;
10961096
match field_number {
10971097
1 => {
1098-
::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.msg_type, 1, &mut self.unknown_fields)?
1098+
if wire_type == ::protobuf::wire_format::WireTypeVarint {self.msg_type = is.read_enum()?;} else { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); }
10991099
},
11001100
2 => {
11011101
if wire_type != ::protobuf::wire_format::WireTypeVarint {
@@ -1945,7 +1945,7 @@ impl ::protobuf::Message for ConfChange {
19451945
self.id = tmp;
19461946
},
19471947
2 => {
1948-
::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.change_type, 2, &mut self.unknown_fields)?
1948+
if wire_type == ::protobuf::wire_format::WireTypeVarint {self.change_type = is.read_enum()?;} else { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); }
19491949
},
19501950
3 => {
19511951
if wire_type != ::protobuf::wire_format::WireTypeVarint {

0 commit comments

Comments
 (0)