Bug 1277 - Move ByteBuffUtils to separate bundle
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / experimenters / OF13ExperimenterActionSerializer.java
1 /*\r
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.openflowjava.protocol.impl.serialization.experimenters;\r
10 \r
11 import io.netty.buffer.ByteBuf;\r
12 \r
13 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;\r
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
18 \r
19 public class OF13ExperimenterActionSerializer implements OFSerializer<Action>,\r
20         HeaderSerializer<Action> {\r
21 \r
22     @Override\r
23     public void serialize(Action action, ByteBuf outBuffer) {\r
24         int actionStartIndex = outBuffer.writerIndex();\r
25         outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE);\r
26         int actionLengthIndex = outBuffer.writerIndex();\r
27         outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);\r
28         ExperimenterAction expAction = action.getAugmentation(ExperimenterAction.class);\r
29         outBuffer.writeInt(expAction.getExperimenter().intValue());\r
30         if (expAction.getData() != null) {\r
31             outBuffer.writeBytes(expAction.getData());\r
32         }\r
33         outBuffer.setShort(actionLengthIndex, outBuffer.writerIndex() - actionStartIndex);\r
34     }\r
35 \r
36     @Override\r
37     public void serializeHeader(Action action, ByteBuf outBuffer) {\r
38         outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE);\r
39         outBuffer.writeShort(EncodeConstants.EXPERIMENTER_IDS_LENGTH);\r
40         ExperimenterAction expAction = action.getAugmentation(ExperimenterAction.class);\r
41         outBuffer.writeInt(expAction.getExperimenter().intValue());\r
42     }\r
43 \r
44 }\r