BUG-3363: code optimization and cleanup - Fix a few warnings
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / action / RegLoadCodec.java
1 package org.opendaylight.openflowjava.nx.codec.action;
2
3 import io.netty.buffer.ByteBuf;
4 import java.math.BigInteger;
5 import org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey;
6 import org.opendaylight.openflowjava.nx.api.NiciraActionSerializerKey;
7 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegLoad;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegLoadBuilder;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.load.grouping.NxActionRegLoadBuilder;
13
14 public class RegLoadCodec extends AbstractActionCodec {
15
16     public static final int LENGTH = 24;
17     public static final byte SUBTYPE = 7; // NXAST_REG_LOAD
18     public static final NiciraActionSerializerKey SERIALIZER_KEY = new NiciraActionSerializerKey(
19             EncodeConstants.OF13_VERSION_ID, ActionRegLoad.class);
20     public static final NiciraActionDeserializerKey DESERIALIZER_KEY = new NiciraActionDeserializerKey(
21             EncodeConstants.OF13_VERSION_ID, SUBTYPE);
22
23     @Override
24     public void serialize(final Action input, final ByteBuf outBuffer) {
25         ActionRegLoad actionRegLoad = ((ActionRegLoad) input.getActionChoice());
26         serializeHeader(LENGTH, SUBTYPE, outBuffer);
27         outBuffer.writeShort(actionRegLoad.getNxActionRegLoad().getOfsNbits());
28         outBuffer.writeInt(actionRegLoad.getNxActionRegLoad().getDst().intValue());
29         outBuffer.writeLong(actionRegLoad.getNxActionRegLoad().getValue().longValue());
30     }
31
32     @Override
33     public Action deserialize(final ByteBuf message) {
34         ActionBuilder actionBuilder = deserializeHeader(message);
35         NxActionRegLoadBuilder nxActionRegLoadBuilder = new NxActionRegLoadBuilder();
36         ActionRegLoadBuilder actionRegLoadBuilder = new ActionRegLoadBuilder();
37         nxActionRegLoadBuilder.setOfsNbits(message.readUnsignedShort());
38         nxActionRegLoadBuilder.setDst(message.readUnsignedInt());
39         nxActionRegLoadBuilder.setValue(BigInteger.valueOf(message.readLong()));
40         actionRegLoadBuilder.setNxActionRegLoad(nxActionRegLoadBuilder.build());
41         actionBuilder.setActionChoice(actionRegLoadBuilder.build());
42         return actionBuilder.build();
43     }
44
45 }