code: public void serialize(final ByteArrayOutputStream outputStream,
                          final SpecificRecord message, final long sequence) throws IOException {
      // Binary encoder for both the header and message.
      final BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(outputStream, null);
      // Write the header and the message.
      headerWriter.write(new Header(sequence, msgMetaClassName), encoder);
      messageWriter.write((TMessage)message, encoder);
      encoder.flush();
    }
docs: Deserialize messages of type TMessage from input outputStream.
  @param outputStream A ByteArrayOutputStream where the message to
  be serialized will be written.
  @param message An Avro message class which implements the Avro SpcificRecord interface.
  @param sequence The numerical position of the message in the outgoing message stream.
  @throws IOException An error occurred writing the message to the outputStream.