diff --git a/Cargo.lock b/Cargo.lock index 71012e1..b0aa94a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,6 +6,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "byteorder" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" + [[package]] name = "bytes" version = "1.0.1" @@ -92,6 +98,7 @@ checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" name = "point-generator" version = "0.0.1" dependencies = [ + "byteorder", "bytes", "rand", "zmq", diff --git a/Cargo.toml b/Cargo.toml index d9d6cc6..22b3471 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ path = "src/main.rs" [dependencies] bytes = "1.0.1" +byteorder = "1.4.2" rand = "0.8.2" zmq = { version = "0.9", features = ['vendored'] } #zeromq = "0.2.0" # Doesn't compile. Complains about Rust issue #54727 diff --git a/src/main.rs b/src/main.rs index f3b2033..1d5c7d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,7 @@ fn main() { let mut messaging_state = MessagingState::Sending; loop { - let point = Point::at_random_range(-1.0f32, 1.0f32, Color::Blue); + let point = Point::at_random_range(-1000.0f32, 1000.0f32, Color::Blue); let bytes = point.to_bytes(); println!("Point : {}", point.debug_string()); diff --git a/src/point.rs b/src/point.rs index fc92203..16e0ca0 100644 --- a/src/point.rs +++ b/src/point.rs @@ -2,6 +2,7 @@ use bytes::{BytesMut, BufMut}; use rand::distributions::Uniform; use rand::Rng; use crate::color::Color; +use byteorder::{WriteBytesExt, LittleEndian, BigEndian}; pub struct Point { @@ -64,7 +65,7 @@ impl Point { pub fn to_bytes(&self) -> Vec { - let mut buf = BytesMut::with_capacity(32); + /*let mut buf = BytesMut::with_capacity(32); buf.put_f32(self.x); buf.put_f32(self.y); buf.put_f32(self.z); @@ -77,7 +78,17 @@ impl Point { buf.put_u32(self.g); buf.put_u32(self.b); buf.put_u32(self.a); - buf.to_vec() + buf.to_vec()*/ + let mut buf = Vec::with_capacity(32); + buf.write_f32::(self.x); + buf.write_f32::(self.y); + buf.write_f32::(self.z); + buf.write_f32::(0.0f32); + buf.write_u32::(self.r); + buf.write_u32::(self.g); + buf.write_u32::(self.b); + buf.write_u32::(self.a); + buf } pub fn location_string(&self) -> String {