Fix most bgp-parser-spi checkstyle violations
[bgpcep.git] / bgp / parser-spi / src / main / java / org / opendaylight / protocol / bgp / parser / spi / extended / community / Inet4SpecificExtendedCommunityCommonUtil.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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.extended.community;
9
10 import static org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractIpv4ExtendedCommunity.INET_LOCAL_ADMIN_LENGTH;
11
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.util.ByteArray;
14 import org.opendaylight.protocol.util.ByteBufWriteUtil;
15 import org.opendaylight.protocol.util.Ipv4Util;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommon;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
18
19 public final class Inet4SpecificExtendedCommunityCommonUtil {
20     private Inet4SpecificExtendedCommunityCommonUtil() {
21         throw new UnsupportedOperationException();
22     }
23
24
25     public static Inet4SpecificExtendedCommunityCommon parseCommon(final ByteBuf buffer) {
26         return new Inet4SpecificExtendedCommunityCommonBuilder()
27                 .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
28                 .setLocalAdministrator(ByteArray.readBytes(buffer, INET_LOCAL_ADMIN_LENGTH))
29                 .build();
30     }
31
32     public static void serializeCommon(
33             final Inet4SpecificExtendedCommunityCommon extComm,
34             final ByteBuf byteAggregator) {
35         ByteBufWriteUtil.writeIpv4Address(extComm.getGlobalAdministrator(), byteAggregator);
36         byteAggregator.writeBytes(extComm.getLocalAdministrator());
37     }
38
39 }