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);
29 /** Constructor of class */
31 LOGGER.debug("Creating OF13Encoder");
35 protected void encode(ChannelHandlerContext ctx, OfHeader msg, ByteBuf out)
37 LOGGER.debug("Encoding");
39 SerializationFactory.messageToBuffer(msg.getVersion(), out, msg);
40 } catch(Exception e) {
41 LOGGER.error("Message serialization failed");
42 LOGGER.error(e.getMessage(), e);
45 if (out.readableBytes() > 0) {
47 ctx.writeAndFlush(out);
49 LOGGER.warn("Translated buffer is empty");