Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upConsider mechanisms to convert &[u32] to &[u8] #37
Comments
This comment has been minimized.
This comment has been minimized.
|
@erickt Can you help me understand the code you posted? I see |
This comment has been minimized.
This comment has been minimized.
|
The |
This comment has been minimized.
This comment has been minimized.
|
@erickt I really can use bytorder like that: let mut buffer = [0u8; STATE_BYTES];
{
let mut p = &mut buffer[..];
for word in self.buffer {
p.write_u32::<NativeEndian>(word);
}
}It looks kind of ugly, but could be moved to additional function. The main reason why I don't want that is that byteorder is dependent on std. It isn't issue, but I want Octavo to use only core so I need find a way to achieve correct conversions between arrays of numbers without byteorder which is wrapper around |
This comment has been minimized.
This comment has been minimized.
|
@hauleth Yup, that looks right to me. No extra APIs needed. :-) With respect to |
This comment has been minimized.
This comment has been minimized.
|
@BurntSushi I have idea how to read from |
This comment has been minimized.
This comment has been minimized.
|
@hauleth That might be OK. I guess the For now, I think I'd recommend writing an iterator over |
This comment has been minimized.
This comment has been minimized.
|
I try to implement that on my own. Do you mind if I borrow some code from you? |
This comment has been minimized.
This comment has been minimized.
|
@hauleth You should be able to implement it on top of the existing methods exposed by |
This comment has been minimized.
This comment has been minimized.
|
Yeah, but I want to make it |
This comment has been minimized.
This comment has been minimized.
|
Right right... Forgot about that. I really do hope to figure something out for byteorder because it does seem like something that should be usable off of libstd. But yeah, I suppose in the mean time, copying code from here might be the thing to do. :-) (It is permissively licensed.) |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I know about license but it is always polite to ask. To be honest I think that Write and Read traits should land in libcore as both are OS independent and it would simplify some work, even without libstd (you sometimes need to write things to memory or similar, this crate is great example). Łukasz Jan Niemier Dnia 9 paź 2015 o godz. 23:06 Andrew Gallant notifications@github.com napisał(a):
|
This comment has been minimized.
This comment has been minimized.
bluss
commented
Oct 10, 2015
|
Moving Read & Write would be nice. Unfortunately |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Oct 10, 2015
|
I'm not sure how much can be done, but let's put the idea out there so we can give it a shot, filed an issue over at rust-lang/rfcs/issues/1314 |
This comment has been minimized.
This comment has been minimized.
|
Today, I'm going to close this, but if there is indeed a problem that is feasible for |
BurntSushi
closed this
Aug 1, 2016
This comment has been minimized.
This comment has been minimized.
burdges
commented
Oct 5, 2016
|
As an aside, I'd think crypto like octavo could just do the |
erickt commentedOct 1, 2015
It makes me a little sad to see
unsafebeing used to convert a&[u32]into a&[u8]in octavo:We really ought to have a place to centralize this functionality so that it's well tested and safe across our ecosystem. Would it make sense to have this functionality be in byteorder?
It'd also be interesting to also support the inverse operation, where a
&[u8]is converted into a(&[u8], &[u32], &[u8]), where the first and last slice are there to read a byte-at-a-time until the the slice is aligned. This style operation could be useful to safely massage a slice into something that can use simd (or at least simd-ish operations over a usize value).cc @huonw, @bluss, @hauleth