2 * Copyright (c) 2013 Cisco Systems, Inc. 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
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.ByteBufUtil;
14 import io.netty.channel.ChannelHandlerContext;
15 import io.netty.handler.codec.ByteToMessageDecoder;
17 import java.util.List;
19 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
20 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
21 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
28 final class BGPByteToMessageDecoder extends ByteToMessageDecoder {
29 private static final Logger LOG = LoggerFactory.getLogger(BGPByteToMessageDecoder.class);
30 private final MessageRegistry registry;
32 public BGPByteToMessageDecoder(final MessageRegistry registry) {
33 this.registry = Preconditions.checkNotNull(registry);
37 protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws BGPDocumentedException,
39 if (in.isReadable()) {
40 LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
41 out.add(this.registry.parseMessage(in));
43 LOG.trace("No more content in incoming buffer.");