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.yangtools.yang.binding.DataObject;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * @author michal.polkorab
19 * @author timotej.kubas
21 public class SerializationFactory {
23 private static final Logger LOGGER = LoggerFactory
24 .getLogger(SerializationFactory.class);
26 * Transforms POJO message into ByteBuf
27 * @param version version used for encoding received message
28 * @param out ByteBuf for storing and sending transformed message
29 * @param message POJO message
31 public static <E extends DataObject> void messageToBuffer(short version, ByteBuf out, E message) {
32 @SuppressWarnings("unchecked")
33 MessageTypeKey<E> msgTypeKey = new MessageTypeKey<>(version, (Class<E>) message.getClass());
34 OFSerializer<E> encoder = EncoderTable.getInstance().getEncoder(msgTypeKey);
35 if (encoder != null) {
36 encoder.messageToBuffer(version, out, message);
38 LOGGER.warn("No correct encoder found in EncoderTable for arguments: " + msgTypeKey.toString());