You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by Youssef Hatem <yo...@rwth-aachen.de> on 2013/10/16 19:25:16 UTC

Tracking the current position of stream decoded BinaryDecoder

Hi,

BinaryDecoder offers getPos() to get the current position which I assume should correspond to the progress the BinaryDecoder has made decoding the passed stream.

However it is inconsistent (perhaps it is a bug, but I suspect so); Calling BinaryDecoder.getPos() after first deserialization gives 0.

I would like to track the exact position of which the BinaryDecoder has reached.

For example if the stream contains a long that is 4 bytes, int that is 3 bytes, and fixed bytes array that is 10 bytes then I would like to get the following information:

Start: pos`=0
After deserializing long => pos`=4
After deserializing int => pos`=6
After deserializing fixed => pos`=15

Is it possible to get this information? Thanks in advance.

Best regards,
Youssef



Re: Tracking the current position of stream decoded BinaryDecoder

Posted by Doug Cutting <cu...@apache.org>.
On Wed, Oct 16, 2013 at 10:25 AM, Youssef Hatem
<yo...@rwth-aachen.de> wrote:
> BinaryDecoder offers getPos() to get the current position which I assume should correspond to the progress the BinaryDecoder has made decoding the passed stream.

That is not a public method in BinaryDecoder, but rather a private
method that refers only to the position with a private buffer.  If you
need to know the number of bytes consumed you may use a direct binary
decoder and pass in an input stream which tracks its position (e.g.,
FileInputStream or RandomAccessFile).

http://avro.apache.org/docs/current/api/java/org/apache/avro/io/DecoderFactory.html#directBinaryDecoder(java.io.InputStream,
org.apache.avro.io.BinaryDecoder)

Doug