Merge "Change the type of some leafs to uint32"
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPExistingBandwidthObjectParser.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.impl.object;
9
10 import java.util.Arrays;
11
12 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
13 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
16
17 /**
18  * Parser for {@link Bandwidth}
19  */
20 public class PCEPExistingBandwidthObjectParser extends AbstractBandwidthParser {
21
22         public static final int CLASS = 5;
23
24         public static final int TYPE = 2;
25
26         private static final int BANDWIDTH_LENGTH = 4;
27
28         public PCEPExistingBandwidthObjectParser(final TlvHandlerRegistry tlvReg) {
29                 super(tlvReg);
30         }
31
32         @Override
33         public byte[] serializeObject(final Object object) {
34                 if (!(object instanceof Bandwidth)) {
35                         throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed BandwidthObject.");
36                 }
37                 final byte[] retBytes = Arrays.copyOf(((Bandwidth) object).getBandwidth().getValue(), BANDWIDTH_LENGTH);
38                 return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), retBytes);
39         }
40
41         @Override
42         public int getObjectType() {
43                 return TYPE;
44         }
45
46         @Override
47         public int getObjectClass() {
48                 return CLASS;
49         }
50 }