All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.ocpjava.protocol.impl.clients.SimpleClientFramer Maven / Gradle / Ivy

There is a newer version: 0.3.3
Show newest version
/*
 * Copyright (c) 2016 Foxconn Corporation and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */


package org.opendaylight.ocpjava.protocol.impl.clients;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Class for decoding incoming messages into message frames.
 *
 * @author Marko Lai 
 */
public class SimpleClientFramer extends ByteToMessageDecoder {
    private static final Logger LOGGER = LoggerFactory.getLogger(SimpleClientFramer.class);

    private List out;    
    private String buf = "";
    
    /**
     * Constructor of class.
     */
    public SimpleClientFramer() {
        LOGGER.debug("Creating OCPFrameDecoder");
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        LOGGER.warn("Unexpected exception from downstream.", cause);
        ctx.close();
    }

    @Override
    protected void decode(ChannelHandlerContext chc, ByteBuf in, List out) throws Exception {
        int len = in.readableBytes();
        byte[] bs = new byte[len];
        in.readBytes(bs);
        out.add(bs);
    }
}