Comments (2)
It should be possible to parse really anything, stateful or not.
I’m not sure of your usecase or what you require to be stateful but this should be relatively straightforward. Eg if you need some state that gets updated you could create a struct that contains the state, and has a method something like:
fn parse(&mut self, bytes: &[u8]) -> Something {
let something = bytes.gread(&mut self.offset).unwrap();
// update any internal state based on what we just parsed, perhaps using information from the parsed thing itself
something
}
So you update your state really whenever you want, using whatever information you need. Again not sure of your particular usecase. Perhaps you could show the kind of state you need to update (and based on what)?
For more complicated examples I’d recommend reading the documentation on custom TryFromCtx implementations or take a look at goblin PE parser which has various stateful aspects, along with custom (dynamically constructed) contexts changing the parsing behavior.
You should be able to do whatever you want :) but id say scroll is useful for quick and easy parsing of structs or simple pods out of byte sequences. Of course you can do whatever with it, and I’m sure people have !
In my experience most complicated things can be solved by deriving Pread on a pod that describes the (packed) data structure in the byte sequence, or if not whenever it doesn’t, custom TryFromCtx will solve the rest. :)
from scroll.
closing; please reopen if you have other questions
from scroll.
Related Issues (20)
- derive(Pread) doesn't work with fields containing an array of structs HOT 6
- derive(Pread) in structs with elements that don't use scroll::Endian as ctx HOT 4
- remove usize pread/pwrite HOT 1
- scroll 1.0 HOT 12
- Repo in Cargo.toml for scroll_derive refers to old repo
- What does the "g" in "gread" stand for? HOT 3
- Publish new versions to crates.io HOT 4
- usize/isize impls must die HOT 1
- tests fail in README.md on published crates HOT 6
- Docs mention lost Gread and Gwrite traits HOT 3
- cargo test --no-default-features fails HOT 2
- Enums derive HOT 10
- Pread, Pwrite with struct containing [u8; 8] do not work anymore with Rust 1.47.0 HOT 18
- src/lib.rs doctest fails on s390x / IBM System Z (big endian) HOT 7
- Writing into a dynamic container HOT 20
- `Pwrite`-ing to a Tokio BufWriter - is it possible?
- Pwrite deriving fails with "unparseable tokens" with struct containing lifetimes? HOT 6
- the trait bound `usize: FromCtx<_>` is not satisfied when testing with derive HOT 1
- Tracking issue for replacing unsafe code. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scroll.