-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Sustenet as a whole, primarily the Client.
Create macros for client. Integrate joining a cluster. Improve both master and cluster. Remove the FromCluster and ToCluster packet sections. Create a ClusterInfo struct to track clusters easier.
- Loading branch information
Showing
6 changed files
with
471 additions
and
140 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/// This calls loop and select! in a single macro. | ||
#[macro_export] | ||
macro_rules! lselect { | ||
($($select_body:tt)*) => { | ||
loop { | ||
tokio::select! { | ||
$($select_body)* | ||
} | ||
} | ||
}; | ||
} | ||
|
||
/// This reads a u8 for the length and then calls read_exact | ||
/// to read the bytes then converts it to a string. | ||
/// | ||
/// This is used in a loop to continue if an error occurs. | ||
#[macro_export] | ||
macro_rules! lread_string { | ||
($reader:expr, $error:expr, $name:expr) => { | ||
{ | ||
let len = match $reader.read_u8().await { | ||
Ok(len) => len, | ||
Err(e) => { | ||
$error(format!("Failed to read the {} len. {:?}", $name, e).as_str()); | ||
continue; | ||
} | ||
} as usize; | ||
|
||
let mut val = vec![0u8; len]; | ||
match $reader.read_exact(&mut val).await { | ||
Ok(_) => (), | ||
Err(e) => { | ||
$error(format!("Failed to read the {}. {:?}", $name, e).as_str()); | ||
continue; | ||
} | ||
}; | ||
|
||
match String::from_utf8(val) { | ||
Ok(val) => val, | ||
Err(e) => { | ||
$error(format!("Failed to convert the {} to a String. {:?}", $name, e).as_str()); | ||
continue; | ||
} | ||
} | ||
} | ||
}; | ||
} |
Oops, something went wrong.