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.core;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.channel.ChannelHandlerContext;
13 import io.netty.handler.codec.MessageToByteEncoder;
14 import io.netty.util.concurrent.Future;
16 import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageListenerWrapper;
17 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Transforms OpenFlow Protocol messages to POJOs
23 * @author michal.polkorab
24 * @author timotej.kubas
26 public class OFEncoder extends MessageToByteEncoder<MessageListenerWrapper> {
28 private static final Logger LOGGER = LoggerFactory.getLogger(OFEncoder.class);
29 private SerializationFactory serializationFactory;
31 /** Constructor of class */
33 LOGGER.trace("Creating OF13Encoder");
37 protected void encode(ChannelHandlerContext ctx, MessageListenerWrapper wrapper, ByteBuf out)
39 LOGGER.trace("Encoding");
41 serializationFactory.messageToBuffer(wrapper.getMsg().getVersion(), out, wrapper.getMsg());
42 } catch(Exception e) {
43 LOGGER.warn("Message serialization failed ", e);
44 Future<Void> newFailedFuture = ctx.newFailedFuture(e);
45 wrapper.getListener().operationComplete(newFailedFuture);
52 * @param serializationFactory
54 public void setSerializationFactory(SerializationFactory serializationFactory) {
55 this.serializationFactory = serializationFactory;