2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.impl.serialization;
11 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
19 * @author michal.polkorab
20 * @author timotej.kubas
22 public class SerializationFactory {
24 private SerializerRegistry registry;
27 * Transforms POJO message into ByteBuf
28 * @param version version used for encoding received message
29 * @param out ByteBuf for storing and sending transformed message
30 * @param message POJO message
32 public void messageToBuffer(short version, ByteBuf out, DataObject message) {
33 OFSerializer<DataObject> serializer = registry.getSerializer(
34 new MessageTypeKey<>(version, message.getImplementedInterface()));
35 serializer.serialize(message, out);
39 * @param serializerRegistry registry with serializers
41 public void setSerializerTable(SerializerRegistry serializerRegistry) {
42 this.registry = serializerRegistry;