org.opendaylight.protocol.bgp.rib.impl.BGPByteToMessageDecoder Maven / Gradle / Ivy
/*
* Copyright (c) 2013 Cisco Systems, Inc. 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.protocol.bgp.rib.impl;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import java.util.List;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
import org.opendaylight.protocol.bgp.parser.spi.PeerConstraint;
import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraintProvider;
import org.opendaylight.protocol.bgp.parser.spi.pojo.PeerSpecificParserConstraintImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final class BGPByteToMessageDecoder extends ByteToMessageDecoder {
private static final Logger LOG = LoggerFactory.getLogger(BGPByteToMessageDecoder.class);
private final MessageRegistry registry;
private final PeerSpecificParserConstraintProvider constraints;
BGPByteToMessageDecoder(final MessageRegistry registry) {
this.constraints = new PeerSpecificParserConstraintImpl();
this.registry = requireNonNull(registry);
}
boolean addDecoderConstraint(final Class classType, final T peerConstraint) {
return this.constraints.addPeerConstraint(classType, peerConstraint);
}
@Override
protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List