import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
-import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.TypeKeyMakerFactory;
+import org.opendaylight.openflowjava.protocol.impl.util.ListSerializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
/**
* Translates PacketOut messages
* @author michal.polkorab
*/
-public class OF10PacketOutInputMessageFactory implements OFSerializer<PacketOutInput> {
+public class OF10PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>, SerializerRegistryInjector {
private static final byte MESSAGE_TYPE = 13;
- private static final int MESSAGE_LENGTH = 16;
-
- private static OF10PacketOutInputMessageFactory instance;
-
- private OF10PacketOutInputMessageFactory() {
- // do nothing, just singleton
- }
-
- /**
- * @return singleton factory
- */
- public static synchronized OF10PacketOutInputMessageFactory getInstance() {
- if (instance == null) {
- instance = new OF10PacketOutInputMessageFactory();
- }
- return instance;
- }
-
- @Override
- public void messageToBuffer(short version, ByteBuf out,
- PacketOutInput message) {
- ByteBufUtils.writeOFHeader(instance, message, out);
- out.writeInt(message.getBufferId().intValue());
- out.writeShort(message.getInPort().getValue().intValue());
- out.writeShort(OF10ActionsSerializer.computeActionsLength(message.getAction()));
- OF10ActionsSerializer.encodeActionsV10(out, message.getAction());
- byte[] data = message.getData();
- if (data != null) {
- out.writeBytes(data);
- }
- }
+ private SerializerRegistry registry;
@Override
- public int computeLength(PacketOutInput message) {
- int length = MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getAction());
+ public void serialize(PacketOutInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeInt(message.getBufferId().intValue());
+ outBuffer.writeShort(message.getInPort().getValue().intValue());
+ int actionsLengthIndex = outBuffer.writerIndex();
+ outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
+ int actionsStartIndex = outBuffer.writerIndex();
+ ListSerializer.serializeList(message.getAction(), TypeKeyMakerFactory
+ .createActionKeyMaker(EncodeConstants.OF10_VERSION_ID), registry, outBuffer);
+ outBuffer.setShort(actionsLengthIndex, outBuffer.writerIndex() - actionsStartIndex);
byte[] data = message.getData();
if (data != null) {
- length += data.length;
+ outBuffer.writeBytes(data);
}
- return length;
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
@Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
}
}