Move entry serialization back to ByteBufWriter
[controller.git] / atomix-storage / src / main / java / io / atomix / storage / journal / ByteBufMapper.java
index cabd48d8bd7d8d428f91ad8d388ca869dd837d2f..a0f6f804494f0e679ac7ebd7a0ccb66d8f5933aa 100644 (file)
 package io.atomix.storage.journal;
 
 import io.netty.buffer.ByteBuf;
+import java.io.IOException;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * Support for serialization of {@link ByteBufJournal} entries.
+ * Support for mapping of {@link ByteBufJournal} entries to and from {@link ByteBuf}s.
  */
 @NonNullByDefault
 public interface ByteBufMapper<T> {
     /**
-     * Converts an object into a series of bytes in a {@link ByteBuf}.
+     * Converts the contents of a {@link ByteBuf} to an object.
      *
-     * @param obj the object
-     * @return resulting buffer
+     * @param index entry index
+     * @param bytes entry bytes
+     * @return resulting object
      */
-    ByteBuf objectToBytes(T obj) ;
+    T bytesToObject(final long index, ByteBuf bytes);
 
     /**
-     * Converts the contents of a {@link ByteBuf} to an object.
+     * Converts an object into a series of bytes in the specified {@link ByteBuf}.
      *
-     * @param buf buffer to convert
-     * @return resulting object
+     * @param obj the object
+     * @param buf target buffer
+     * @throws IOException if an I/O error occurs
      */
-    T bytesToObject(ByteBuf buf);
+    void objectToBytes(T obj, ByteBuf buf) throws IOException;
 }