Function Encoder.writeUnionType

Call this method to write the tag of a union.

abstract void writeUnionType (
  ulong unionTypeIndex,
  string unionTypeName
) @safe;

As an example of usage, let's say you want to write a union, whose second branch is a record of type "thing" consisting of an Long field and a Boolean field. Your code would look something like this:

out.writeUnionStart();
out.writeUnionIndex(1, "thing");
out.writeRecordStart();
out.writeLong(record.getField("longField").getValue!long);
out.writeBoolean(record.getField("boolField").getValue!bool);
out.writeRecordEnd();
out.writeUnionEnd();

Throws

AvroTypeException If this is a stateful writer and a map is not expected