2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.rsvp.parser.spi.subobjects;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.opendaylight.protocol.util.ByteArray;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
18 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
20 public final class PathKeyUtils {
21 private PathKeyUtils() {
25 public static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
26 .subobjects.subobject.type.path.key._case.PathKey parsePathKey(final int pceIdFLength, final ByteBuf buffer) {
27 return new PathKeyBuilder()
28 .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
29 .setPceId(new PceId(ByteArray.readBytes(buffer, pceIdFLength)))
33 public static ByteBuf serializePathKey(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
34 .rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKey pk) {
35 final ByteBuf body = Unpooled.buffer();
36 final PathKey pathKey = pk.getPathKey();
37 checkArgument(pathKey != null, "PathKey is mandatory.");
38 ByteBufUtils.write(body, pathKey.getValue());
40 final PceId pceId = pk.getPceId();
41 checkArgument(pceId != null, "PceId is mandatory.");
42 body.writeBytes(pceId.getValue());