Javadoc update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / ExperimenterInputMessageFactory.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
3 \r
4 import io.netty.buffer.ByteBuf;\r
5 \r
6 import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
7 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;\r
9 \r
10 /**\r
11  * Translates Experimenter messages\r
12  * @author michal.polkorab\r
13  * @author timotej.kubas\r
14  */\r
15 public class ExperimenterInputMessageFactory implements OFSerializer<ExperimenterInput>{\r
16 \r
17     /** Code type of Experimenter message */\r
18     public static final byte MESSAGE_TYPE = 4;\r
19     private static final byte MESSAGE_LENGTH = 8;\r
20     private static ExperimenterInputMessageFactory instance;\r
21     \r
22     private ExperimenterInputMessageFactory() {\r
23         // do nothing, just singleton\r
24     }\r
25     \r
26     /**\r
27      * @return singleton factory\r
28      */\r
29     public static synchronized ExperimenterInputMessageFactory getInstance() {\r
30         if (instance == null) {\r
31             instance = new ExperimenterInputMessageFactory();\r
32         }\r
33         return instance;\r
34     }\r
35     \r
36     @Override\r
37     public void messageToBuffer(short version, ByteBuf out,\r
38             ExperimenterInput message) {\r
39         ByteBufUtils.writeOFHeader(instance, message, out);\r
40         out.writeInt(message.getExperimenter().intValue());\r
41         out.writeInt(message.getExpType().intValue());\r
42         byte[] data = message.getData();\r
43         if (data != null) {\r
44             out.writeBytes(data);\r
45         }\r
46     }\r
47 \r
48     @Override\r
49     public int computeLength(ExperimenterInput message) {\r
50         int length = MESSAGE_LENGTH + 2 * (Integer.SIZE / Byte.SIZE);\r
51         byte[] data = message.getData();\r
52         if (data != null) {\r
53             length += data.length;\r
54         }\r
55         return length;\r
56     }\r
57 \r
58     @Override\r
59     public byte getMessageType() {\r
60         return MESSAGE_TYPE;\r
61     }\r
62     \r
63 }\r