Now it works. It was endianness

This commit is contained in:
Brandon Thomas
2021-01-14 01:13:51 -05:00
parent 4416b53c3f
commit e6be343c76
4 changed files with 22 additions and 3 deletions
Generated
+7
View File
@@ -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",
+1
View File
@@ -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
+1 -1
View File
@@ -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());
+13 -2
View File
@@ -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<u8> {
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::<LittleEndian>(self.x);
buf.write_f32::<LittleEndian>(self.y);
buf.write_f32::<LittleEndian>(self.z);
buf.write_f32::<LittleEndian>(0.0f32);
buf.write_u32::<LittleEndian>(self.r);
buf.write_u32::<LittleEndian>(self.g);
buf.write_u32::<LittleEndian>(self.b);
buf.write_u32::<LittleEndian>(self.a);
buf
}
pub fn location_string(&self) -> String {