Fix findbugs violations in openflowjava
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / SerializationFactory.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.serialization;
10
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
14 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16
17 /**
18  * Serializes messages.
19  *
20  * @author michal.polkorab
21  * @author timotej.kubas
22  */
23 public class SerializationFactory {
24
25     private final SerializerRegistry registry;
26
27     public SerializationFactory(SerializerRegistry registry) {
28         this.registry = registry;
29     }
30
31     /**
32      * Transforms POJO message into ByteBuf.
33      *
34      * @param version version used for encoding received message
35      * @param out ByteBuf for storing and sending transformed message
36      * @param message POJO message
37      */
38     public void messageToBuffer(short version, ByteBuf out, DataObject message) {
39         OFSerializer<DataObject> serializer = registry.getSerializer(
40                 new MessageTypeKey<>(version, message.getImplementedInterface()));
41         serializer.serialize(message, out);
42     }
43 }