generated from PlexSheep/baserepo
Compare commits
3 commits
e3ac4c60ba
...
0a6072c478
Author | SHA1 | Date | |
---|---|---|---|
0a6072c478 | |||
20b8f7a582 | |||
33260726a1 |
7 changed files with 30 additions and 9 deletions
|
@ -10,7 +10,7 @@ default-members = [".", "members/libpt-core"]
|
|||
|
||||
[workspace.package]
|
||||
publish = true
|
||||
version = "0.4.3"
|
||||
version = "0.5.0"
|
||||
edition = "2021"
|
||||
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
||||
license = "MIT"
|
||||
|
@ -29,7 +29,7 @@ categories = [
|
|||
anyhow = "1.0.79"
|
||||
thiserror = "1.0.56"
|
||||
libpt-core = { version = "0.4.0", path = "members/libpt-core" }
|
||||
libpt-bintols = { version = "0.4.0", path = "members/libpt-bintols" }
|
||||
libpt-bintols = { version = "0.5.0", path = "members/libpt-bintols" }
|
||||
libpt-log = { version = "0.4.2", path = "members/libpt-log" }
|
||||
|
||||
[package]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "libpt-bintols"
|
||||
publish.workspace = true
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
|
|
|
@ -25,4 +25,4 @@ pub const YOBI: u128 = 2u128.pow(80);
|
|||
// use libpt_core;
|
||||
pub mod datalayout;
|
||||
pub mod display;
|
||||
pub mod split_numbers;
|
||||
pub mod split;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
//! Sometimes, you need a large integer in the form of many bytes, so split into [u8].
|
||||
//! Rust provides
|
||||
|
||||
|
||||
/// Split unsigned integers into a [Vec] of [u8]s
|
||||
///
|
||||
/// Say you have the [u32] 1717 (binary: `00000000 00000000 00000110 10110101 `). This number would
|
||||
|
@ -14,7 +15,7 @@
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use libpt_bintols::split_numbers::*;
|
||||
/// # use libpt_bintols::split::*;
|
||||
///
|
||||
/// let x: u32 = 1717;
|
||||
///
|
||||
|
@ -22,7 +23,7 @@
|
|||
/// ```
|
||||
pub fn unsigned_to_vec<T>(num: T) -> Vec<u8>
|
||||
where
|
||||
u128: std::convert::From<T>,
|
||||
u128: std::convert::From<T>
|
||||
{
|
||||
let mut num: u128 = num.into();
|
||||
if num == 0 {
|
|
@ -1,4 +1,4 @@
|
|||
use libpt_bintols::split_numbers::*;
|
||||
use libpt_bintols::split::*;
|
||||
|
||||
#[test]
|
||||
fn split_u128() {
|
|
@ -19,7 +19,7 @@ name = "libpt"
|
|||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
libpt = { version = "0.4.3", path = "../.." }
|
||||
libpt = { version = "0.5.0", path = "../.." }
|
||||
pyo3 = { version = "0.19.0", features = ["full"] }
|
||||
anyhow.workspace = true
|
||||
|
||||
|
|
|
@ -2,10 +2,29 @@ use pyo3::prelude::*;
|
|||
|
||||
use libpt::bintols as origin;
|
||||
|
||||
mod display {
|
||||
mod split {
|
||||
use libpt::bintols::split as origin;
|
||||
use pyo3::prelude::*;
|
||||
|
||||
#[pyfunction]
|
||||
pub fn split_int(data: u128) -> Vec<u8> {
|
||||
origin::unsigned_to_vec(data)
|
||||
}
|
||||
|
||||
/// implement a python module in Rust
|
||||
pub fn submodule(py: Python, parent: &PyModule) -> PyResult<()> {
|
||||
let module = PyModule::new(py, "split")?;
|
||||
|
||||
module.add_function(wrap_pyfunction!(split_int, module)?)?;
|
||||
|
||||
parent.add_submodule(module)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
mod display {
|
||||
use libpt::bintols::display as origin;
|
||||
use pyo3::prelude::*;
|
||||
|
||||
#[pyfunction]
|
||||
pub fn bytes_to_bin(data: &[u8]) -> String {
|
||||
|
@ -50,6 +69,7 @@ pub fn submodule(py: Python, parent: &PyModule) -> PyResult<()> {
|
|||
module.add("YOBI", origin::YOBI)?;
|
||||
|
||||
display::submodule(py, module)?;
|
||||
split::submodule(py, module)?;
|
||||
|
||||
parent.add_submodule(module)?;
|
||||
Ok(())
|
||||
|
|
Reference in a new issue