9ebe84d518e60ff0d60d2c3688ef2b5632c47b6b
[bgpcep.git] / bgp / parser-spi / src / main / java / org / opendaylight / protocol / bgp / parser / spi / AttributeParser.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.parser.spi;
9
10 import io.netty.buffer.ByteBuf;
11 import javax.annotation.Nonnull;
12 import javax.annotation.Nullable;
13 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
14 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
16
17 /**
18  * Common interface for attribute parser implementation.
19  */
20 public interface AttributeParser {
21     /**
22      * Parses attribute from ByteBuf buffer.
23      *
24      * @param buffer Encoded attribute body in ByteBuf.
25      * @param builder Path attributes builder. Guaranteed to contain all valid attributes whose type is numerically
26      *        lower than this attribute's type.
27      */
28     void parseAttribute(@Nonnull ByteBuf buffer, @Nonnull AttributesBuilder builder) throws BGPDocumentedException, BGPParsingException;
29
30     /**
31      * Invokes {@link #parseAttribute(ByteBuf, AttributesBuilder)}, so the constraint is omitted. Override for specific parser behavior.
32      *
33      * @param buffer Encoded attribute body in ByteBuf.
34      * @param builder Path attributes builder. Guaranteed to contain all valid attributes whose type is numerically
35      *        lower than this attribute's type.
36      * @param constraint Peer specific constraints.
37      * @throws BGPDocumentedException
38      * @throws BGPParsingException
39      */
40     default void parseAttribute(@Nonnull final ByteBuf buffer, @Nonnull final AttributesBuilder builder, @Nullable final PeerSpecificParserConstraint constraint)
41             throws BGPDocumentedException, BGPParsingException {
42         parseAttribute(buffer, builder);
43     }
44 }