Function Encoder.writeArrayStart

Call this method to start writing an array.

abstract void writeArrayStart() @safe;

When starting to serialize an array, call [writeArrayStart]. Then, before writing any data for any item call [setItemCount] followed by a sequence of [startItem()] and the item itself. The number of [startItem()] should match the number specified in [setItemCount]. When actually writing the data of the item, you can call any [Encoder] method (e.g., [writeLong]). When all items of the array have been written, call [writeArrayEnd].

As an example, let's say you want to write an array of records, the record consisting of an Long field and a Boolean field. Your code would look something like this:

out.writeArrayStart();
out.setItemCount(list.size());
foreach (GenericRecord r; list) {
  out.startItem();
  out.writeLong(r.longField);
  out.writeBoolean(r.boolField);
}
out.writeArrayEnd();

Throws

AvroTypeException If this is a stateful writer and an array is not expected