Hi,

My app receives Avro blocks in raw byte form, and I'm having trouble
reading them.

My function's input is a ByteString that contains all the bytes for a given
Avro block, i.e all the bytes contained between 2 sync points of an Avro
file.

This is what I've got so far:

    public void forEachRecordInBlock(
        ByteString rawBlockBytes, Schema schema, Consumer<GenericRecord>
consumer) throws IOException {
        GenericDatumReader<GenericRecord> datumReader = new
GenericDatumReader<>(schema);
        BinaryDecoder decoder =
DecoderFactory.get().binaryDecoder(rawBlockBytes.toByteArray(), null);
        while(true) {
            try {
                GenericRecord record = datumReader.read(null, decoder);
                consumer.accept(record);
            } catch (EOFException e) {
                // Finished reading all records in the block
                return;
            }
        }
    }

However, it doesn't work as I'm getting this error:

org.apache.avro.AvroRuntimeException: Malformed data. Length is negative:
-39

Do you know what I might be missing? How could I make this work?

Thanks!

Julien

Reply via email to