Java tutorial
/** * This file is part of SynchronizeFX. * * Copyright (C) 2013-2014 Saxonia Systems AG * * SynchronizeFX is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SynchronizeFX is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with SynchronizeFX. If not, see <http://www.gnu.org/licenses/>. */ package de.saxsys.synchronizefx.netty.tcp; import de.saxsys.synchronizefx.netty.base.Codec; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import io.netty.handler.codec.LengthFieldPrepender; /** * A codec that collects coherent messages by prepending the size of the message to the message itself. * * @author Raik Bieniek */ class LengthFieldBasedCodec implements Codec { @Override public void addToPipeline(final ChannelPipeline pipeline) { pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4)); pipeline.addLast(new LengthFieldPrepender(4)); } }