X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=bgp%2Frib-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fbgp%2Frib%2Fimpl%2FBGPByteToMessageDecoder.java;h=4ceb42de8592defb1b6cd4880d8d3731bae04fd9;hb=71c2d5bc6998723e28cc6bdf09b376966b19db57;hp=c5d9f4c7be88d68d1706db8316d9b8a5be23e11f;hpb=088c6f4843bb229a7bf5a89a5c178e9866c26d79;p=bgpcep.git diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPByteToMessageDecoder.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPByteToMessageDecoder.java index c5d9f4c7be..4ceb42de85 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPByteToMessageDecoder.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPByteToMessageDecoder.java @@ -7,6 +7,8 @@ */ package org.opendaylight.protocol.bgp.rib.impl; +import com.google.common.base.Preconditions; + import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelHandlerContext; @@ -20,35 +22,25 @@ import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; - /** * */ final class BGPByteToMessageDecoder extends ByteToMessageDecoder { - private final static Logger LOG = LoggerFactory.getLogger(BGPByteToMessageDecoder.class); - private final MessageRegistry registry; + private static final Logger LOG = LoggerFactory.getLogger(BGPByteToMessageDecoder.class); + private final MessageRegistry registry; - public BGPByteToMessageDecoder(final MessageRegistry registry) { - this.registry = Preconditions.checkNotNull(registry); - } + public BGPByteToMessageDecoder(final MessageRegistry registry) { + this.registry = Preconditions.checkNotNull(registry); + } - @Override - protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List out) throws Exception { - if (in.readableBytes() == 0) { - LOG.debug("No more content in incoming buffer."); - return; - } - in.markReaderIndex(); - try { - LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); - final byte[] bytes = new byte[in.readableBytes()]; - in.readBytes(bytes); - out.add(this.registry.parseMessage(bytes)); - } catch (BGPParsingException | BGPDocumentedException e) { - LOG.debug("Failed to decode protocol message", e); - this.exceptionCaught(ctx, e); - } - in.discardReadBytes(); - } + @Override + protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List out) throws BGPDocumentedException, + BGPParsingException { + if (in.isReadable()) { + LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); + out.add(this.registry.parseMessage(in)); + } else { + LOG.trace("No more content in incoming buffer."); + } + } }