Remove useless UnsupportedOperationExceptions
[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         // Hidden on purpose
22     }
23
24     public static Inet4SpecificExtendedCommunityCommon parseCommon(final ByteBuf buffer) {
25         return new Inet4SpecificExtendedCommunityCommonBuilder()
26                 .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
27                 .setLocalAdministrator(ByteArray.readBytes(buffer, INET_LOCAL_ADMIN_LENGTH))
28                 .build();
29     }
30
31     public static void serializeCommon(final Inet4SpecificExtendedCommunityCommon extComm,
32             final ByteBuf byteAggregator) {
33         ByteBufWriteUtil.writeIpv4Address(extComm.getGlobalAdministrator(), byteAggregator);
34         byteAggregator.writeBytes(extComm.getLocalAdministrator());
35     }
36 }