-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move protos to a separate crate (#247)
* Move protos to a separate crate Makes Raft a workspace project Signed-off-by: Nick Cameron <nrc@ncameron.org> * Satisfy Rustfmt Signed-off-by: Nick Cameron <nrc@ncameron.org>
- Loading branch information
Showing
11 changed files
with
83 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[package] | ||
name = "raft-proto" | ||
version = "0.1.0" | ||
authors = ["The TiKV Project Developers"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
keywords = ["raft", "distributed-systems", "ha"] | ||
repository = "https://github.com/pingcap/raft-rs" | ||
homepage = "https://github.com/pingcap/raft-rs" | ||
documentation = "https://docs.rs/raft-proto" | ||
description = "Protocol definitions for the rust language implementation of the Raft algorithm." | ||
categories = ["algorithms", "database-implementations"] | ||
build = "build.rs" | ||
|
||
[features] | ||
default = [] | ||
gen = [] | ||
|
||
[build-dependencies] | ||
protobuf-build = "0.6" | ||
|
||
[dependencies] | ||
bytes = "0.4.11" | ||
lazy_static = "1.3.0" | ||
prost = "0.5" | ||
prost-derive = "0.5" | ||
protobuf = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
pub use crate::prost::eraftpb; | ||
|
||
mod prost; | ||
|
||
pub mod prelude { | ||
pub use crate::eraftpb::{ | ||
ConfChange, ConfChangeType, ConfState, Entry, EntryType, HardState, Message, MessageType, | ||
Snapshot, SnapshotMetadata, | ||
}; | ||
} | ||
|
||
pub mod util { | ||
use crate::eraftpb::{ConfChange, ConfChangeType, ConfState}; | ||
|
||
// Bring some consistency to things. The protobuf has `nodes` and it's not really a term that's used anymore. | ||
impl ConfState { | ||
/// Get the voters. This is identical to `nodes`. | ||
#[inline] | ||
pub fn get_voters(&self) -> &[u64] { | ||
&self.nodes | ||
} | ||
} | ||
|
||
impl<Iter1, Iter2> From<(Iter1, Iter2)> for ConfState | ||
where | ||
Iter1: IntoIterator<Item = u64>, | ||
Iter2: IntoIterator<Item = u64>, | ||
{ | ||
fn from((voters, learners): (Iter1, Iter2)) -> Self { | ||
let mut conf_state = ConfState::default(); | ||
conf_state.mut_nodes().extend(voters.into_iter()); | ||
conf_state.mut_learners().extend(learners.into_iter()); | ||
conf_state | ||
} | ||
} | ||
|
||
impl From<(u64, ConfState)> for ConfChange { | ||
fn from((start_index, state): (u64, ConfState)) -> Self { | ||
let mut change = ConfChange::default(); | ||
change.set_change_type(ConfChangeType::BeginMembershipChange); | ||
change.set_configuration(state); | ||
change.set_start_index(start_index); | ||
change | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters