Search in sources :

Example 1 with OutputBuffer

use of org.apache.cassandra.io.util.OutputBuffer in project eiger by wlloyd.

the class SerDeUtils method serializeWithSchema.

/**
     * Serializes a single object along with its Schema. NB: For performance critical areas, it is <b>much</b>
     * more efficient to store the Schema independently.
     * @param o Object to serialize
     */
public static <T extends SpecificRecord> ByteBuffer serializeWithSchema(T o) throws IOException {
    OutputBuffer buff = new OutputBuffer();
    BinaryEncoder enc = new BinaryEncoder(buff);
    enc.writeString(new Utf8(o.getSchema().toString()));
    SpecificDatumWriter<T> writer = new SpecificDatumWriter<T>(o.getSchema());
    writer.write(o, enc);
    enc.flush();
    return ByteBuffer.wrap(buff.asByteArray());
}
Also used : BinaryEncoder(org.apache.avro.io.BinaryEncoder) Utf8(org.apache.avro.util.Utf8) OutputBuffer(org.apache.cassandra.io.util.OutputBuffer) SpecificDatumWriter(org.apache.avro.specific.SpecificDatumWriter)

Example 2 with OutputBuffer

use of org.apache.cassandra.io.util.OutputBuffer in project eiger by wlloyd.

the class SerDeUtils method serialize.

/**
     * Serializes a single object.
     * @param o Object to serialize
     */
public static <T extends SpecificRecord> ByteBuffer serialize(T o) throws IOException {
    OutputBuffer buff = new OutputBuffer();
    BinaryEncoder enc = new BinaryEncoder(buff);
    SpecificDatumWriter<T> writer = new SpecificDatumWriter<T>(o.getSchema());
    writer.write(o, enc);
    enc.flush();
    return ByteBuffer.wrap(buff.asByteArray());
}
Also used : BinaryEncoder(org.apache.avro.io.BinaryEncoder) OutputBuffer(org.apache.cassandra.io.util.OutputBuffer) SpecificDatumWriter(org.apache.avro.specific.SpecificDatumWriter)

Aggregations

BinaryEncoder (org.apache.avro.io.BinaryEncoder)2 SpecificDatumWriter (org.apache.avro.specific.SpecificDatumWriter)2 OutputBuffer (org.apache.cassandra.io.util.OutputBuffer)2 Utf8 (org.apache.avro.util.Utf8)1