Fix most bgp-parser-impl checkstyle
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / message / update / MultiExitDiscriminatorAttributeParser.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.impl.message.update;
9
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.Unpooled;
12 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
13 import org.opendaylight.protocol.bgp.parser.BGPError;
14 import org.opendaylight.protocol.bgp.parser.BGPTreatAsWithdrawException;
15 import org.opendaylight.protocol.bgp.parser.spi.AbstractAttributeParser;
16 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
17 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
18 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
19 import org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDisc;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDiscBuilder;
24
25 public final class MultiExitDiscriminatorAttributeParser extends AbstractAttributeParser
26         implements AttributeSerializer {
27     public static final int TYPE = 4;
28
29     @Override
30     public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
31             final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint)
32                     throws BGPDocumentedException, BGPTreatAsWithdrawException {
33         final int readable = buffer.readableBytes();
34         if (readable != 4) {
35             throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR,
36                 "MULTI_EXIT_DISC has to have length 4, but has %s", readable);
37         }
38         builder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(buffer.readUnsignedInt()).build());
39     }
40
41     @Override
42     public void serializeAttribute(final Attributes attribute, final ByteBuf byteAggregator) {
43         final MultiExitDisc multiExitDisc = attribute.getMultiExitDisc();
44         if (multiExitDisc != null) {
45             final Long med = multiExitDisc.getMed();
46             if (med != null) {
47                 AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, Unpooled.copyInt(med.intValue()),
48                     byteAggregator);
49             }
50         }
51     }
52 }