Added more serialization factories
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / HelloInputMessageFactory.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.core.OFFrameDecoder;\r
7 import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;\r
9 \r
10 /**\r
11  * @author michal.polkorab\r
12  *\r
13  */\r
14 public class HelloInputMessageFactory implements OFSerializer<HelloInput>{\r
15 \r
16     /** Code type of Hello message */\r
17     public static final byte MESSAGE_TYPE = 0;\r
18     private static HelloInputMessageFactory instance;\r
19     \r
20     private HelloInputMessageFactory() {\r
21         // do nothing, just singleton\r
22     }\r
23     \r
24     /**\r
25      * @return singleton factory\r
26      */\r
27     public static HelloInputMessageFactory getInstance() {\r
28         if (instance == null) {\r
29             instance = new HelloInputMessageFactory();\r
30         }\r
31         return instance;\r
32     }\r
33 \r
34     @Override\r
35     public void messageToBuffer(short version, ByteBuf out, HelloInput message) {\r
36         out.writeByte(message.getVersion());\r
37         out.writeByte(MESSAGE_TYPE);\r
38         out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER);\r
39         out.writeInt(message.getXid().intValue());\r
40         // TODO - fill list of elements into ByteBuf, check length too\r
41     }\r
42     \r
43     \r
44 \r
45     \r
46     \r
47 }\r