28393a5e9cce232a057574714918b9e9ed970db0
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / instruction / WriteActionsInstructionSerializer.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.serialization.instruction;
10
11 import io.netty.buffer.ByteBuf;
12
13 import java.util.List;
14
15 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
19
20 /**
21  * @author michal.polkorab
22  *
23  */
24 public class WriteActionsInstructionSerializer extends AbstractActionInstructionSerializer {
25
26     @Override
27     public void serialize(final Instruction instruction, final ByteBuf outBuffer) {
28         int startIndex = outBuffer.writerIndex();
29         outBuffer.writeShort(getType());
30         WriteActionsCase actionsCase = (WriteActionsCase) instruction.getInstructionChoice();
31         if (actionsCase != null) {
32             List<Action> actions = actionsCase.getWriteActions().getAction();
33             writeActions(actions, outBuffer, startIndex);
34         } else {
35             outBuffer.writeShort(InstructionConstants.STANDARD_INSTRUCTION_LENGTH);
36             outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
37         }
38     }
39
40     @Override
41     protected int getType() {
42         return InstructionConstants.WRITE_ACTIONS_TYPE;
43     }
44
45 }