// Path: src/main/java/org/sharedmq/primitives/MappedByteArrayStorageKeyStorageAdapter.java
// public class MappedByteArrayStorageKeyStorageAdapter implements StorageAdapter<MappedByteArrayStorageKey> {
// 
//     private static final MappedByteArrayStorageKeyStorageAdapter instance
//             = new MappedByteArrayStorageKeyStorageAdapter();
// 
//     public static MappedByteArrayStorageKeyStorageAdapter getInstance() {
//         return instance;
//     }
// 
//     @Override
//     public int getRecordSize() {
//         return 4 * 2 + 8;
//     }
// 
//     @Override
//     public void store(ByteBuffer buffer, MappedByteArrayStorageKey key) {
// 
//         if (key == null) {
//             throw new IllegalArgumentException(
//                     "The MappedByteArrayStorageKeyStorageAdapter does not support null records.");
//         }
// 
//         buffer.putInt(key.getSegmentNumber());
//         buffer.putInt(key.getRecordNumber());
//         buffer.putLong(key.getRecordId());
//     }
// 
//     @Override
//     public MappedByteArrayStorageKey load(ByteBuffer buffer) {
//         int segmentNumber = buffer.getInt();
//         int recordNumber = buffer.getInt();
//         long recordId = buffer.getLong();
//         return new MappedByteArrayStorageKey(segmentNumber, recordNumber, recordId);
//     }
// }
// 
// Path: src/main/java/org/sharedmq/primitives/StorageAdapter.java
// public interface StorageAdapter<TRecord> {
//     /**
//      * Returns the size of one record in bytes.
//      */
//     int getRecordSize();
// 
//     /**
//      * Writes the given record to the buffer at current buffer position.
//      *
//      * @param buffer The buffer to write the record to.
//      * @param record The record to store.
//      */
//     void store(ByteBuffer buffer, TRecord record);
// 
//     /**
//      * Reads a record from the buffer at current buffer position.
//      *
//      * @param buffer The buffer to read from.
//      * @return The record at the given buffer position.
//      */
//     TRecord load(ByteBuffer buffer) throws IOException;
// }


import org.sharedmq.primitives.MappedByteArrayStorageKeyStorageAdapter;
import org.sharedmq.primitives.StorageAdapter;
import java.nio.ByteBuffer;
package org.sharedmq.internals;



/**
 * A storage adapter for the {@link MessageHeader}.
 */
public class MessageHeaderStorageAdapter implements StorageAdapter<MessageHeader> {

    // We assume that such timestamp can never occur (292269055 BC).
    private static final long TimestampNullValue = Long.MIN_VALUE;

    private static final byte NullMarker = 0;
    private static final byte NotNullMarker = 1;

    private static final MessageHeaderStorageAdapter instance = new MessageHeaderStorageAdapter();

    private MappedByteArrayStorageKeyStorageAdapter keyStorageAdapter
            = MappedByteArrayStorageKeyStorageAdapter.getInstance();

    public static StorageAdapter<MessageHeader> getInstance() {
        return instance;
    }

    @Override
    public int getRecordSize() {
        return 1 + 2 * 4 + 4 * 8 + keyStorageAdapter.getRecordSize();
    }

    @Override
    public void store(ByteBuffer buffer, MessageHeader header) {

        if (header == null) {
            buffer.put(NullMarker);
// Path: src/main/java/org/sharedmq/primitives/MappedByteArrayStorageKeyStorageAdapter.java
// public class MappedByteArrayStorageKeyStorageAdapter implements StorageAdapter<MappedByteArrayStorageKey> {
// 
//     private static final MappedByteArrayStorageKeyStorageAdapter instance
//             = new MappedByteArrayStorageKeyStorageAdapter();
// 
//     public static MappedByteArrayStorageKeyStorageAdapter getInstance() {
//         return instance;
//     }
// 
//     @Override
//     public int getRecordSize() {
//         return 4 * 2 + 8;
//     }
// 
//     @Override
//     public void store(ByteBuffer buffer, MappedByteArrayStorageKey key) {
// 
//         if (key == null) {
//             throw new IllegalArgumentException(
//                     "The MappedByteArrayStorageKeyStorageAdapter does not support null records.");
//         }
// 
//         buffer.putInt(key.getSegmentNumber());
//         buffer.putInt(key.getRecordNumber());
//         buffer.putLong(key.getRecordId());
//     }
// 
//     @Override
//     public MappedByteArrayStorageKey load(ByteBuffer buffer) {
//         int segmentNumber = buffer.getInt();
//         int recordNumber = buffer.getInt();
//         long recordId = buffer.getLong();
//         return new MappedByteArrayStorageKey(segmentNumber, recordNumber, recordId);
//     }
// }
// 
// Path: src/main/java/org/sharedmq/primitives/StorageAdapter.java
// public interface StorageAdapter<TRecord> {
//     /**
//      * Returns the size of one record in bytes.
//      */
//     int getRecordSize();
// 
//     /**
//      * Writes the given record to the buffer at current buffer position.
//      *
//      * @param buffer The buffer to write the record to.
//      * @param record The record to store.
//      */
//     void store(ByteBuffer buffer, TRecord record);
// 
//     /**
//      * Reads a record from the buffer at current buffer position.
//      *
//      * @param buffer The buffer to read from.
//      * @return The record at the given buffer position.
//      */
//     TRecord load(ByteBuffer buffer) throws IOException;
// }


// Path: src/main/java/org/sharedmq/internals/MessageHeaderStorageAdapter.java
import org.sharedmq.primitives.MappedByteArrayStorageKeyStorageAdapter;
import org.sharedmq.primitives.StorageAdapter;
import java.nio.ByteBuffer;

package org.sharedmq.internals;



/**
 * A storage adapter for the {@link MessageHeader}.
 */
public class MessageHeaderStorageAdapter implements StorageAdapter<MessageHeader> {

    // We assume that such timestamp can never occur (292269055 BC).
    private static final long TimestampNullValue = Long.MIN_VALUE;

    private static final byte NullMarker = 0;
    private static final byte NotNullMarker = 1;

    private static final MessageHeaderStorageAdapter instance = new MessageHeaderStorageAdapter();

    private MappedByteArrayStorageKeyStorageAdapter keyStorageAdapter
            = MappedByteArrayStorageKeyStorageAdapter.getInstance();

    public static StorageAdapter<MessageHeader> getInstance() {
        return instance;
    }

    @Override
    public int getRecordSize() {
        return 1 + 2 * 4 + 4 * 8 + keyStorageAdapter.getRecordSize();
    }

    @Override
    public void store(ByteBuffer buffer, MessageHeader header) {

        if (header == null) {
            buffer.put(NullMarker);
            return;