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.concepts.Bandwidth;
11 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
12 import org.opendaylight.protocol.pcep.PCEPObject;
13 import org.opendaylight.protocol.pcep.impl.PCEPObjectParser;
14 import org.opendaylight.protocol.pcep.object.PCEPExistingPathBandwidthObject;
15 import org.opendaylight.protocol.util.ByteArray;
18 * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPExistingPathBandwidthObject
19 * PCEPExistingPathBandwidthObject}
21 public class PCEPExistingPathBandwidthObjectParser implements PCEPObjectParser {
23 private static final int BANDWIDTH_F_LENGTH = 4;
26 public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException {
28 throw new IllegalArgumentException("Array of bytes is mandatory");
29 if (bytes.length != BANDWIDTH_F_LENGTH)
30 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: " + BANDWIDTH_F_LENGTH + ".");
32 return new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.bytesToFloat(bytes)), processed, ignored);
36 public byte[] put(PCEPObject obj) {
37 if (!(obj instanceof PCEPExistingPathBandwidthObject))
38 throw new IllegalArgumentException("Unknown PCEPObject instance.");
40 return ByteArray.floatToBytes((float) ((PCEPExistingPathBandwidthObject) obj).getBandwidth().getBytesPerSecond());