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.deserialization;
11 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * @author michal.polkorab
20 * @author timotej.kubas
22 public abstract class DeserializationFactory {
24 private static final Logger LOGGER = LoggerFactory
25 .getLogger(DeserializationFactory.class);
28 * Transforms ByteBuf into correct POJO message
30 * @param version version decoded from OpenFlow protocol message
31 * @return correct POJO as DataObject
33 public static DataObject bufferToMessage(ByteBuf rawMessage, short version) {
34 DataObject dataObject = null;
35 short type = rawMessage.readUnsignedByte();
36 rawMessage.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
38 MessageTypeCodeKey msgTypeCodeKey = new MessageTypeCodeKey(version, type);
39 OFDeserializer<?> decoder = DecoderTable.getInstance().getDecoder(msgTypeCodeKey);
40 if (decoder != null) {
41 dataObject = decoder.bufferToMessage(rawMessage, version);
43 LOGGER.warn("No correct decoder found in DecoderTable for arguments: " + msgTypeCodeKey.toString());