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;
15 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * Transforms OpenFlow Protocol messages to POJOs
22 * @author michal.polkorab
23 * @author timotej.kubas
25 public class OFEncoder extends MessageToByteEncoder<OfHeader> {
27 private static final Logger LOGGER = LoggerFactory.getLogger(OFEncoder.class);
28 private SerializationFactory serializationFactory;
30 /** Constructor of class */
32 LOGGER.trace("Creating OF13Encoder");
36 protected void encode(ChannelHandlerContext ctx, OfHeader msg, ByteBuf out)
38 LOGGER.trace("Encoding");
40 serializationFactory.messageToBuffer(msg.getVersion(), out, msg);
41 } catch(Exception e) {
42 LOGGER.error("Message serialization failed");
43 LOGGER.error(e.getMessage(), e);
50 * @param serializationFactory
52 public void setSerializationFactory(SerializationFactory serializationFactory) {
53 this.serializationFactory = serializationFactory;