generated from PlexSheep/baserepo
bintols
This commit is contained in:
parent
3c8a2d9661
commit
ebac3201cd
|
@ -1,7 +1,7 @@
|
||||||
//* # See what's behind the datatypes of Rust
|
//* # See what's behind the datatypes of Rust
|
||||||
//*
|
//*
|
||||||
//* This Crate shows off how datatypes of rust are stored in memory.
|
//* This Crate shows off how datatypes of rust are stored in memory.
|
||||||
use std::any::{TypeId, type_name};
|
use crate::display::{bytes_to_bin, byte_bit_display};
|
||||||
|
|
||||||
/// ## Investigate the internal representation of variables
|
/// ## Investigate the internal representation of variables
|
||||||
///
|
///
|
||||||
|
@ -31,29 +31,9 @@ macro_rules! investigate_memory_layout {
|
||||||
byte_bit_display(std::mem::align_of_val(item)),
|
byte_bit_display(std::mem::align_of_val(item)),
|
||||||
byte_bit_display(memory.len()),
|
byte_bit_display(memory.len()),
|
||||||
memory,
|
memory,
|
||||||
bytes_to_bin(&memory),
|
bytes_to_bin(&memory)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bytes_to_bin(v: &[u8]) -> String {
|
|
||||||
if v.len() > 8 || v.len() < 1 {
|
|
||||||
return String::from("(impractical size for dump)")
|
|
||||||
}
|
|
||||||
let mut s = format!("0b{:08b}", v.first().unwrap());
|
|
||||||
for i in 1..v.len() {
|
|
||||||
s.push_str(&format!("_{:08b}", v[i]));
|
|
||||||
if i % 8 == 0 {
|
|
||||||
s.push_str("\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn byte_bit_display(v: usize) -> String
|
|
||||||
{
|
|
||||||
format!("{:07} B = {:08} bit", v.clone(), v * 8)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
//* # Tools that help display binary values, data sizes, etc
|
||||||
|
|
||||||
|
/// ## Get the binary representation for a Byte array [`&[u8]`]
|
||||||
|
///
|
||||||
|
/// ### Arguments
|
||||||
|
/// * `data` - The data you are trying to dump
|
||||||
|
pub fn bytes_to_bin(data: &[u8]) -> String {
|
||||||
|
let mut s = format!("0b{:08b}", data.first().unwrap());
|
||||||
|
for i in 1..data.len() {
|
||||||
|
s.push_str(&format!("_{:08b}", data[i]));
|
||||||
|
if i % 8 == 0 {
|
||||||
|
s.push_str("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Quickly format a number of Bytes [`usize`] with the corresponding
|
||||||
|
/// number of bits
|
||||||
|
pub fn byte_bit_display(data: usize) -> String {
|
||||||
|
format!("{:07} B = {:08} bit", data.clone(), data * 8)
|
||||||
|
}
|
|
@ -1,2 +1,3 @@
|
||||||
use pt_core;
|
// use pt_core;
|
||||||
pub mod datalayout;
|
pub mod datalayout;
|
||||||
|
pub mod display;
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pt-core"
|
name = "pt-core"
|
||||||
version = "0.1.0"
|
publish.workspace = true
|
||||||
edition = "2021"
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
authors.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
description.workspace = true
|
||||||
|
readme.workspace = true
|
||||||
|
homepage.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
keywords.workspace = true
|
||||||
|
categories.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pt-log"
|
name = "pt-log"
|
||||||
version = "0.1.0"
|
publish.workspace = true
|
||||||
edition = "2021"
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
authors.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
description.workspace = true
|
||||||
|
readme.workspace = true
|
||||||
|
homepage.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
keywords.workspace = true
|
||||||
|
categories.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
|
|
Reference in New Issue