com.kolibrifx.napo.mq.MessageToMQMessageSerializerAdapter Maven / Gradle / Ivy
/*
* Copyright (c) 2010-2017, KolibriFX AS. Licensed under the Apache License, version 2.0.
*/
package com.kolibrifx.napo.mq;
import java.nio.ByteBuffer;
import com.kolibrifx.mq.core.MQMessageSerializer;
import com.kolibrifx.napo.MessageSerializer;
import com.kolibrifx.napo.nio.ByteBufferMessageReader;
import com.kolibrifx.napo.nio.ByteBufferMessageWriter;
/**
* Adapter from MessageByteBufferSerializers (general) to ByteCoreSerializers (MQ).
*
* It is recommended that you NOT subclass this implementation.
*/
public class MessageToMQMessageSerializerAdapter implements MQMessageSerializer {
private final MessageSerializer underlying;
public MessageToMQMessageSerializerAdapter(final MessageSerializer underlying, final Class elementClass) {
this.underlying = underlying;
}
@Override
public void serialize(final ByteBuffer out, final T message) {
final ByteBufferMessageWriter writer = new ByteBufferMessageWriter(out);
underlying.serialize(writer, message);
}
@Override
public T deserialize(final ByteBuffer data) {
return underlying.deserialize(new ByteBufferMessageReader(data));
}
}