Move ipv4/ipv6 ByteBuf utilities to Ipv{4,6}Util
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / route / target / RouteTargetIpv4Handler.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.impl.message.update.extended.communities.route.target;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.protocol.util.Ipv4Util;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4Builder;
14 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
15
16 /**
17  * Route Target Ipv4 Handler.
18  *
19  * @author Claudio D. Gasparini
20  */
21 public final class RouteTargetIpv4Handler {
22     private RouteTargetIpv4Handler() {
23         // Hidden on purpose
24     }
25
26     public static void serialize(final RouteTargetIpv4 routeTarget, final ByteBuf byteAggregator) {
27         Ipv4Util.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
28         ByteBufUtils.writeOrZero(byteAggregator, routeTarget.getLocalAdministrator());
29     }
30
31     public static RouteTargetIpv4 parse(final ByteBuf buffer) {
32         return new RouteTargetIpv4Builder()
33                 .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
34                 .setLocalAdministrator(ByteBufUtils.readUint16(buffer))
35                 .build();
36     }
37 }