New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to pass binary data #31
Comments
Will take a look into it this weekend, seems simple enough. |
Sure! I'm working with @willbrowningme on one library that uses OpenPGP keys. Currently we need to armor all keys (basically base64 encode) and that makes keys stored in db 33% bigger than necessary. You can check out this function: https://gitlab.com/willbrowning/anonaddy-sequoia/-/blob/master/src/lib.rs#L186 It should accept and return just bytes and the calling PHP code would save and that from the database. |
I see, would something like this work? pub extern fn test(ex: &mut ExecutionData, ret: &mut Zval) {
let x: Vec<u8> = vec![1, 2, 3, 4, 5];
ret.set_string(String::from_utf8_lossy(x));
} and then in PHP $x = unpack('C*, test()); Not sure if this would work in your situation but seemed to work for me when testing. I will keep looking into a generic impl for other integer types as well, because I don't think the same would work for types like i16, i32 etc. |
I need to check the actual example that you have. Thanks for help! |
Could you have a look at #32 and tell me what you think? Seems to work for most types that /// Unpacks a binary u8 array
pub extern fn skel_unpack(ex: &mut ExecutionData, ret: &mut Zval) {
let mut packed = Arg::new("packed", DataType::String);
parse_args!(ex, packed);
let value = unsafe { packed.zval().unwrap().binary::<u8>(); };
dbg!(value);
}
/// Packs a binary u8 array
pub extern fn skel_pack(ex: &mut ExecutionData, ret: &mut Zval) {
ret.set_binary(vec![12u8, 13, 14, 15, 20, 25]);
} $x = [15, 30, 45];
skel_unpack(pack('C*', ...$x));
// [15, 30, 45] from Rust
$x = unpack('C*', skel_pack());
var_dump($x); // array(6) [12, 13, 14, 15, 20, 25] |
David, sorry for the super late reply but I did write a small proof-of-concept code using Thanks for your time and hard work on this lib! I really appreciate it. |
No worries, thanks for confirming it works. I'll merge it into master now. |
Hi!
I'd like to pass binary data between PHP and the Rust crate. As far as I understand both on PHP side this is just a string while on rust side they'd be slices of u8 (or vectors?).
Is something like that possible or planned?
Thanks again for this great library!
The text was updated successfully, but these errors were encountered: