Reduce use oif ByteBufWriteUtil in pcep-segment-routing
[bgpcep.git] / rsvp / spi / src / main / java / org / opendaylight / protocol / rsvp / parser / spi / subobjects / UnnumberedInterfaceSubobjectUtils.java
1 /*
2  * Copyright (c) 2015 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.rsvp.parser.spi.subobjects;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.Unnumbered;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
15 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
16
17 public final class UnnumberedInterfaceSubobjectUtils {
18     private UnnumberedInterfaceSubobjectUtils() {
19         // Hidden on purpose
20     }
21
22     public static UnnumberedCase parseUnnumeredInterface(final ByteBuf buffer) {
23         return new UnnumberedCaseBuilder()
24                 .setUnnumbered(new UnnumberedBuilder()
25                     .setRouterId(ByteBufUtils.readUint32(buffer))
26                     .setInterfaceId(ByteBufUtils.readUint32(buffer))
27                     .build())
28                 .build();
29     }
30
31     public static void serializeUnnumeredInterface(final Unnumbered unnumbered, final ByteBuf body) {
32         ByteBufUtils.writeMandatory(body, unnumbered.getRouterId(), "RouterId");
33         ByteBufUtils.writeMandatory(body, unnumbered.getInterfaceId(), "InterfaceId");
34     }
35 }