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.object;
10 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
11 import org.opendaylight.protocol.pcep.PCEPObject;
12 import org.opendaylight.protocol.pcep.impl.PCEPObjectParser;
13 import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth;
17 * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject
18 * PCEPRequestedPathBandwidthObject}
20 public class PCEPRequestedPathBandwidthObjectParser implements PCEPObjectParser {
22 private static final int BANDWIDTH_F_LENGTH = 4;
25 public PCEPObject parse(final byte[] bytes, final boolean processed, final boolean ignored) throws PCEPDeserializerException {
26 if (bytes == null || bytes.length == 0)
27 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
28 if (bytes.length != BANDWIDTH_F_LENGTH)
29 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: "
30 + BANDWIDTH_F_LENGTH + ".");
32 return new PCEPRequestedPathBandwidthObject(new Bandwidth(bytes), processed, ignored);
36 public byte[] put(final PCEPObject obj) {
37 if (!(obj instanceof PCEPRequestedPathBandwidthObject))
38 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass()
39 + ". Needed PCEPRequestedPathBandwidthObject.");
41 return ((PCEPRequestedPathBandwidthObject) obj).getBandwidth().getValue();