Skip to content

[noob question] How do I parse a vector (Bytes)? #248

Answered by kitlith
anndavism asked this question in Q&A
Discussion options

You must be logged in to vote

minor heads up, you can tell markdown what language your code block contains, and then github will syntax highlight it for you. (I edited your original post, you can click the edit button to observe how that was done)

onto the actual question: what I think you're asking is "Given a set of bytes in memory, how can I tell binrw to parse it?" Your friend here is std::io::Cursor, which wraps byte-like objects (slices, arrays, vectors) and implements io::Read/Seek/Write, as applicable. That's either going to be Cursor::new(bytes), Cursor::new(&bytes), Cursor::new(bytes.as_slice()), or something similar. (If you're in a no_std environment, binrw provides a polyfill in the binrw::io module.)

Fro…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by anndavism
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants