316d970fd28ead8920f2bd88f5a7130286300d59
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / experimenters / ExperimenterActionDeserializer.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.deserialization.experimenters;\r
10 \r
11 import io.netty.buffer.ByteBuf;\r
12 \r
13 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;\r
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;\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.augments.rev131002.ExperimenterActionBuilder;\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;\r
21 \r
22 /**\r
23  * @author michal.polkorab\r
24  *\r
25  */\r
26 public class ExperimenterActionDeserializer implements OFDeserializer<Action>,\r
27         HeaderDeserializer<Action> {\r
28 \r
29     @Override\r
30     public Action deserializeHeader(ByteBuf input) {\r
31         ActionBuilder builder = new ActionBuilder();\r
32         input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
33         builder.setType(Experimenter.class);\r
34         input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
35         ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder();\r
36         expBuilder.setExperimenter(input.readUnsignedInt());\r
37         builder.addAugmentation(ExperimenterAction.class, expBuilder.build());\r
38         return builder.build();\r
39     }\r
40 \r
41     @Override\r
42     public Action deserialize(ByteBuf input) {\r
43         ActionBuilder builder = new ActionBuilder();\r
44         input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
45         builder.setType(Experimenter.class);\r
46         int length = input.readUnsignedShort();\r
47         // subtract experimenter header length\r
48         length -= EncodeConstants.EXPERIMENTER_IDS_LENGTH;\r
49         ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder();\r
50         expBuilder.setExperimenter(input.readUnsignedInt());\r
51         if (length > 0) {\r
52             byte[] data = new byte[length];\r
53             input.readBytes(data);\r
54             expBuilder.setData(data);\r
55         }\r
56         builder.addAugmentation(ExperimenterAction.class, expBuilder.build());\r
57         return builder.build();\r
58     }\r
59 \r
60 }\r