package com.oriordank.mapdbserializers;

import org.apache.activemq.store.PListEntry;
import org.apache.activemq.util.ByteSequence;
import org.mapdb.Serializer;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.Serializable;

public class PListEntrySerializer implements Serializer<PListEntry>, Serializable {
    @Override
    public void serialize(DataOutput out, PListEntry value) throws IOException {
        out.writeUTF(value.getId());
        ByteSequence bs = value.getByteSequence();
        out.writeInt(bs.getLength());
        out.write(bs.getData(), bs.getOffset(), bs.getLength());
        out.writeLong((Long)value.getLocator());
    }

    @Override
    public PListEntry deserialize(DataInput in, int available) throws IOException {
        String id = in.readUTF();
        int length = in.readInt();
        byte[] bytes = new byte[length];
        in.readFully(bytes);
        ByteSequence bs = new ByteSequence(bytes);
        long locator = in.readLong();
        PListEntry entry = new PListEntry(id, bs, locator);
        return entry;
    }

    @Override
    public int fixedSize() {
        return -1;
    }
}

@@ -125,16 +125,75 @@
 quence;%0A
+import org.mapdb.DataInput2;%0Aimport org.mapdb.DataOutput2;%0A
 import o
@@ -213,16 +213,16 @@
 alizer;%0A
-
 %0Aimport 
@@ -604,21 +604,33 @@
     
-out.writeInt(
+DataOutput2.packInt(out, 
 bs.g
@@ -719,22 +719,34 @@
     
-out.writeLong(
+DataOutput2.packLong(out, 
 (Lon
@@ -932,19 +932,31 @@
 h = 
-in.read
+DataInput2.unpack
 Int(
+in
 );%0A 
@@ -1102,20 +1102,32 @@
 r = 
-in.read
+DataInput2.unpack
 Long(
+in
 );%0A 

Use DataIO2 Packed longs and ints