2 * Copyright (c) 2013 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.pcep.impl.subobject;
10 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
11 import org.opendaylight.protocol.pcep.spi.LabelParser;
12 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
13 import org.opendaylight.protocol.util.ByteArray;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Type1Label;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1LabelBuilder;
19 import com.google.common.primitives.UnsignedInts;
21 public class Type1LabelParser implements LabelParser, LabelSerializer {
23 public static final int CTYPE = 1;
25 public static final int LABEL_LENGTH = 4;
28 public LabelType parseLabel(final byte[] buffer) throws PCEPDeserializerException {
29 if (buffer == null || buffer.length == 0)
30 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
31 if (buffer.length != LABEL_LENGTH)
32 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: " + LABEL_LENGTH
35 return new Type1LabelBuilder().setType1Label(UnsignedInts.toLong(ByteArray.bytesToInt(buffer))).build();
39 public byte[] serializeSubobject(final CLabel subobject) {
40 if (!(subobject instanceof Type1Label))
41 throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass() + ". Needed Type1Label.");
43 return ByteArray.longToBytes(((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1Label) subobject).getType1Label().longValue());
47 public int getType() {