Skip to content

Commit

Permalink
Use the old way to read enum (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
BusyJay authored and hicqu committed Jun 11, 2018
1 parent 01424b8 commit a6671be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ categories = ["algorithms", "database-implementations"]

[dependencies]
log = "0.4.1"
protobuf = "2.0"
protobuf = "~2.0.0"
quick-error = "1.2.1"
rand = "0.4"
fxhash = "0.2.1"
Expand Down
13 changes: 13 additions & 0 deletions generate-proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
protoc proto/eraftpb.proto --rust_out=src/
# TODO: remove this once stepancheg/rust-protobuf#233 is resolved.
python <<EOF
import re
with open("src/eraftpb.rs") as reader:
src = reader.read()
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)
with open("src/eraftpb.rs", "w") as writer:
writer.write(res)
EOF
8 changes: 4 additions & 4 deletions src/eraftpb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is generated by rust-protobuf 1.6.0. Do not edit
// This file is generated by rust-protobuf 2.0.2. Do not edit
// @generated

// https://github.com/Manishearth/rust-clippy/issues/702
Expand Down Expand Up @@ -163,7 +163,7 @@ impl ::protobuf::Message for Entry {
let (field_number, wire_type) = is.read_tag_unpack()?;
match field_number {
1 => {
::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.entry_type, 1, &mut self.unknown_fields)?
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)); }
},
2 => {
if wire_type != ::protobuf::wire_format::WireTypeVarint {
Expand Down Expand Up @@ -1095,7 +1095,7 @@ impl ::protobuf::Message for Message {
let (field_number, wire_type) = is.read_tag_unpack()?;
match field_number {
1 => {
::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.msg_type, 1, &mut self.unknown_fields)?
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)); }
},
2 => {
if wire_type != ::protobuf::wire_format::WireTypeVarint {
Expand Down Expand Up @@ -1945,7 +1945,7 @@ impl ::protobuf::Message for ConfChange {
self.id = tmp;
},
2 => {
::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.change_type, 2, &mut self.unknown_fields)?
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)); }
},
3 => {
if wire_type != ::protobuf::wire_format::WireTypeVarint {
Expand Down

0 comments on commit a6671be

Please sign in to comment.