add bintols

This commit is contained in:
Christoph J. Scherr 2023-09-20 14:28:40 +02:00
parent 999c753d3e
commit 482e246bc8
4 changed files with 72 additions and 53 deletions

View File

@ -1,8 +1,10 @@
[workspace] [workspace]
resolver = "2"
publish = false publish = false
members = [ members = [
"members/pt", "members/pt",
"members/pt-core", "members/pt-core",
"members/pt-bintols",
"members/pt-math", "members/pt-math",
"members/pt-bin", "members/pt-bin",
"members/pt-log", "members/pt-log",
@ -17,56 +19,3 @@ default-members = [
"members/pt-log", "members/pt-log",
"members/pt-math", "members/pt-math",
] ]
[package]
publish = false
autobins = true
default-run = "pt"
name = "libpt"
version = "0.1.6"
edition = "2021"
authors = ["Christoph J. Scherr <software@cscherr.de>"]
license = "GPL-3.0-or-later"
description = "Personal multitool"
readme = "README.md"
homepage = "https://git.cscherr.de/PlexSheep/pt"
repository = "https://git.cscherr.de/PlexSheep/pt"
keywords = ["cli", "python", "scriptable", "pyo3", "library"]
categories = ["command-line-utilities", "development-tools", "development-tools::ffi"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "pt"
crate-type = ["cdylib", "rlib"]
[[bin]]
name = "pt"
path = "src/bin/main/mod.rs"
[[bin]]
name = "ccc"
path = "src/bin/ccc/mod.rs"
[dependencies]
clap = { version = "4.3.11", features = ["derive"] }
clap-num = "1.0.2"
clap-verbosity-flag = "2.0.1"
env_logger = "0.10.0"
humantime = "2.1.0"
num = "0.4.0"
num-traits = "0.2.16"
openssl = "0.10.55"
openssl-sys = "0.9.90"
pyo3 = "0.18.1"
regex = "1.9.1"
reqwest = { version = "0.11.18", features = ["blocking"] }
serde = { version = "1.0.171", features = ["derive"] }
serde_json = "1.0.102"
signal-hook = "0.3.15"
tracing = "0.1.37"
tracing-appender = "0.2.2"
tracing-subscriber = "0.3.17"
[dev-dependencies]
gag = "1.0.0"

View File

@ -0,0 +1,10 @@
[package]
name = "pt-bintols"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
pt-core = { version = "0.1.0", path = "../pt-core" }
pt-log = { version = "0.1.0", path = "../pt-log" }

View File

@ -0,0 +1,59 @@
//* # See what's behind the datatypes of Rust
//*
//* This Crate shows off how datatypes of rust are stored in memory.
use std::any::{TypeId, type_name};
/// ## Investigate the internal representation of variables
///
/// Takes 1. the Type and 2. a [`Vec`] of items (of that datatype).
#[macro_export]
macro_rules! investigate_memory_layout {
($t:ty, $v:tt) => {
println!("Type:\t{}", type_name::<$t>());
println!("\talign:\t{:?} B", std::mem::align_of::<$t>());
println!("\tID:\t{:?}\n", TypeId::of::<$t>());
println!("\tItems:");
unsafe {
for (index, item) in $v.iter().enumerate() {
let pointer = item as *const $t;
let mut memory: [u8; std::mem::size_of::<$t>()] = std::mem::transmute(item.clone());
memory.reverse();
println!("\
\t{index:02x}\titem:\t\t{item:?}\n\
\t\tpointer: \t{:X?}\n\
\t\talign: \t{}\n\
\t\tsize: \t{}\n\
\t\tmemory: \t{:X?}\n\
\t\tbin mem: \t{}\n\
\t\tnote: \tmemory order reversed\n\
",
pointer,
byte_bit_display(std::mem::align_of_val(item)),
byte_bit_display(memory.len()),
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)
}

View File

@ -0,0 +1 @@
pub mod datalayout;