Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Reading/Writing of UUID #1

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/types/misc/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,28 @@ impl Uuid {
* Reads a signed 128-bit ( 16 bytes ) uuid string from the stream.
*/
pub fn read(stream: &mut BinaryStream) -> Result<String> {
let bytes = match stream.read(16) {
Ok(bytes) => bytes,
// MIGHT NEED TO FORMAT LIKE WRITE?
// MIGHT ALSO JUST GO BACK TO ORIGINAL?
let mut bytes_m = match stream.read(8) {
Ok(bytes_m) => bytes_m,
Err(err) => return Err(err)
};

let mut bytes_l = match stream.read(8) {
Ok(bytes_l) => bytes_l,
Err(err) => return Err(err)
};

bytes_m.reverse();
bytes_l.reverse();

let mut uuid = String::new();
for byte in bytes {

for byte in bytes_m {
uuid.push_str(&format!("{:02X}", byte));
}

for byte in bytes_l {
uuid.push_str(&format!("{:02X}", byte));
}

Expand All @@ -41,11 +56,23 @@ impl Uuid {
pub fn write(stream: &mut BinaryStream, value: String) {
let mut data = value.replace("-", "");
data = data.to_uppercase();

let mut bytes = Vec::new();
for i in 0..16 {
for i in 0..8 {
let byte = u8::from_str_radix(&data[i * 2..i * 2 + 2], 16).unwrap();
bytes.push(byte);
}

bytes.reverse();
stream.write(bytes);
bytes = Vec::new();

for i in 8..16 {
let byte = u8::from_str_radix(&data[i * 2..i * 2 + 2], 16).unwrap();
bytes.push(byte);
}

bytes.reverse();
stream.write(bytes)
}
}
Loading