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.PathKeySubobject;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
19 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
21 public final class PathKeyUtils {
22 private PathKeyUtils() {
26 public static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
27 .subobjects.subobject.type.path.key._case.PathKey parsePathKey(final int pceIdFLength, final ByteBuf buffer) {
28 return new PathKeyBuilder()
29 .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
30 .setPceId(new PceId(ByteArray.readBytes(buffer, pceIdFLength)))
34 public static ByteBuf serializePathKey(final PathKeySubobject 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());