"Added more deserialization factories & their unit tests"
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / MultipartReplyMessageFactory.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
3 \r
4 import io.netty.buffer.ByteBuf;\r
5 \r
6 import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;\r
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;\r
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;\r
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;\r
11 \r
12 /**\r
13  * @author timotej.kubas\r
14  * @author michal.polkorab\r
15  */\r
16 public class MultipartReplyMessageFactory implements OFDeserializer<MultipartReplyMessage> {\r
17 \r
18     private static MultipartReplyMessageFactory instance;\r
19     private static final byte PADDING_IN_MULTIPART_REPLY_HEADER = 4;\r
20     \r
21     private MultipartReplyMessageFactory() {\r
22         // singleton\r
23     }\r
24     \r
25     /**\r
26      * @return singleton factory\r
27      */\r
28     public static MultipartReplyMessageFactory getInstance(){\r
29         if (instance == null){\r
30             instance = new MultipartReplyMessageFactory();\r
31         }\r
32         return instance;\r
33     }\r
34 \r
35     @Override\r
36     public MultipartReplyMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
37         MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();\r
38         builder.setVersion(version);\r
39         builder.setXid(rawMessage.readUnsignedInt());\r
40         builder.setType(MultipartType.forValue(rawMessage.readUnsignedShort()));\r
41         builder.setFlags(new MultipartRequestFlags((rawMessage.readUnsignedShort() & 0x01) > 0));\r
42         rawMessage.skipBytes(PADDING_IN_MULTIPART_REPLY_HEADER);\r
43         // TODO - implement body\r
44         //mrmb.setBody(rawMessage.readBytes(rawMessage.readableBytes()).array());\r
45         return builder.build();\r
46     } \r
47 }\r