org.radarbase.data.RemoteSchemaEncoder Maven / Gradle / Ivy
package org.radarbase.data;
import java.io.IOException;
import org.apache.avro.Schema;
import org.apache.avro.SchemaValidationException;
import org.apache.avro.generic.GenericData;
import org.apache.avro.specific.SpecificData;
import org.apache.avro.specific.SpecificRecord;
import org.radarbase.producer.rest.AvroDataMapper;
import org.radarbase.producer.rest.AvroDataMapperFactory;
import org.radarbase.producer.rest.ParsedSchemaMetadata;
/**
* Encodes data according to an Avro schema to the format and schema of the server.
*/
public class RemoteSchemaEncoder implements AvroEncoder {
private final boolean binary;
/**
* Schema encoder.
* @param binary true if the server wants binary encoding, false if it wants JSON encoding.
*/
public RemoteSchemaEncoder(boolean binary) {
this.binary = binary;
}
@Override
public AvroWriter writer(Schema schema, Class extends T> clazz) {
return new SchemaEncoderWriter<>(schema, clazz);
}
private class SchemaEncoderWriter implements AvroWriter {
private final AvroEncoder recordEncoder;
private AvroEncoder.AvroWriter