Get the number of bytes parsed from `nom`

Hello all!

Is it possible to get the number of bytes parsed from nom? I am trying to use nom inside an implementation of tokio_io::codec::Decoder and I need to know how many bytes were parsed in order to remove them from a growing BytesMut.

1 Like

Doesn't nom return both what bytes we're parsed and the remaining slice? You can just call .len() on that no?

2 Likes

nom parsers return the parsed object which could be of any type. For example nom::be_u64 parses a big-endian u64 and returns a u64, not 8 bytes.

You know what? I think taking the len() of the original BytesMut and subtracting the len() of the unparsed slice might give me the length of the parsed slice.
Thanks @cbreeden :slight_smile: