1 package com.github.davidmoten.rx.buffertofile; 2 3 import java.io.DataInput; 4 import java.io.DataOutput; 5 import java.io.IOException; 6 7 public interface DataSerializer<T> { 8 9 /** 10 * Serializes an object to a data stream. 11 * 12 * @param output 13 * the data stream 14 * @param t 15 * the object to serialize 16 * @throws IOException 17 * exception 18 */ 19 void serialize(DataOutput output, T t) throws IOException; 20 21 /** 22 * Deserializes the bytes pointed by {@code input}. 23 * 24 * @param input 25 * input data to read from 26 * @return deserialized object 27 * @throws IOException 28 * exception 29 */ 30 T deserialize(DataInput input) throws IOException; 31 32 /** 33 * Returns the serialized length if constant other wise returns 0 to 34 * indicate variable length (which may force more copying in memory and be a 35 * bit slower). 36 * 37 * @return serialized length or 0 if variable 38 */ 39 int size(); 40 }