--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.instruction;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.List;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EnhancedTypeKeyMakerFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ListSerializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public abstract class AbstractActionInstructionSerializer extends AbstractInstructionSerializer\r
+ implements SerializerRegistryInjector {\r
+\r
+ private SerializerRegistry registry;\r
+\r
+ @Override\r
+ public void serialize(Instruction instruction, ByteBuf outBuffer) {\r
+ int startIndex = outBuffer.writerIndex();\r
+ outBuffer.writeShort(getType());\r
+ if (instruction.getAugmentation(ActionsInstruction.class) != null) {\r
+ List<Action> actions = instruction.getAugmentation(ActionsInstruction.class).getAction();\r
+ int lengthIndex = outBuffer.writerIndex();\r
+ outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);\r
+ ByteBufUtils.padBuffer(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION, outBuffer);\r
+ ListSerializer.serializeList(actions, EnhancedTypeKeyMakerFactory\r
+ .createActionKeyBuilder(EncodeConstants.OF13_VERSION_ID), getRegistry(), outBuffer);\r
+ int instructionLength = outBuffer.writerIndex() - startIndex;\r
+ outBuffer.setShort(lengthIndex, instructionLength);\r
+ } else {\r
+ outBuffer.writeShort(InstructionConstants.STANDARD_INSTRUCTION_LENGTH);\r
+ ByteBufUtils.padBuffer(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION, outBuffer);\r
+ }\r
+ }\r
+\r
+ protected SerializerRegistry getRegistry() {\r
+ return registry;\r
+ }\r
+\r
+ @Override\r
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {\r
+ registry = serializerRegistry;\r
+ }\r
+}\r