Hello Gents,

Ok I came up with this design:

package org.apache.iotdb.tsfile.common.serialization;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;

public interface IDataSerializer<T, V> {
    int serializeTo(T data, OutputStream outputStream) throws IOException;
    int serializeTo(T data, ByteBuffer buffer);
    T deserializeFrom(ByteBuffer buffer, V options);
    T deserializeFrom(InputStream inputStream, V options);
}


And i have for example, something like this:
public class PageHeaderSerializer implements IDataSerializer<PageHeader,
TSDataType> {

 @Override
 public int serializeTo(PageHeader data, OutputStream outputStream) throws
IOException {
// code
 }
 @Override
 public int serializeTo(PageHeader data, ByteBuffer buffer) {
/// snip.
 }

 @Override
 public PageHeader deserializeFrom(ByteBuffer buffer, TSDataType options) {
///
}

 @Override
 public PageHeader deserializeFrom(InputStream inputStream, TSDataType
options) {
 // snippet
 }
}
In this way we have a class that has the respobility of serialization. We
delegate the serialization to an appropriate class without breaking the
interface.
This is the first step.

BR,
Giorgio

Reply via email to