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
9 package org.opendaylight.protocol.rsvp.parser.spi.subobjects;
11 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
13 import com.google.common.base.Preconditions;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.opendaylight.protocol.util.ByteArray;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
21 public class CommonPathKeyParser {
22 protected CommonPathKeyParser() {
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 final int pathKey = buffer.readUnsignedShort();
29 final byte[] pceId = ByteArray.readBytes(buffer, pceIdFLength);
30 final PathKeyBuilder pBuilder = new PathKeyBuilder();
31 pBuilder.setPceId(new PceId(pceId));
32 pBuilder.setPathKey(new PathKey(pathKey));
33 return pBuilder.build();
36 public static ByteBuf serializePathKey(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
37 .rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKey pk) {
38 final ByteBuf body = Unpooled.buffer();
39 Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
40 writeUnsignedShort(pk.getPathKey().getValue(), body);
41 Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
42 body.writeBytes(pk.getPceId().getBinary());