-
Hi all, I am starting a small project where I am parsing some simple binary structures. I have read through all the tutorials and documentation (which are excellent), but I am still getting stuck. I want to parse (given a slice of bytes) the following format:
Assume that I have a Then I want to parse from
I am trying to get something like (which obviously is wrong, but I haven't been able to understand all the things that I am doing wrong):
Once I get the above working, I would use it to have 2 public methods: Can I get some guidance on how to get the above working? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
It'd help to know what problems you are having with it so we can have an idea of how to steer things. I'm goin to make some guesses The first problem I'm noticing is your return type is
The last You mentioned the name should be alphanumeric which this doesn't check. You could do
This parser never commits to the parse, making it so whatever runs next will process the same For more, see the next one
This isn't doing any validation that there is enough data to slice, causing a Instead try using Hmm, I think I should rename that to |
Beta Was this translation helpful? Give feedback.
It'd help to know what problems you are having with it so we can have an idea of how to steer things. I'm goin to make some guesses
The first problem I'm noticing is your return type is
impl Parser
but you are trying to returnPResult<Bank16View, E>
because you have(input)
at the end. If you remove that, you'll be returning a closure (FnMut
) which, when the signature is correct, will matchimpl Parser
and work.The last
verify
should be redundant astake
guarantees that only 4 tokens were consumed.You mentioned the name should be alphanumeric which this doesn't check. You could do
take_while(4, (b'a'..='z', b'A'..='Z'…