BUG-47: more subobject models
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / subobject / RROGeneralizedLabelSubobjectParser.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.subobject;
9
10 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
11 import org.opendaylight.protocol.pcep.subobject.RROGeneralizedLabelSubobject;
12 import org.opendaylight.protocol.pcep.subobject.RROLabelSubobject;
13
14 public class RROGeneralizedLabelSubobjectParser implements RROLabelParser {
15
16     @Override
17     public RROLabelSubobject parse(byte[] cutBytes, boolean upStream) throws PCEPDeserializerException {
18         if (cutBytes == null || cutBytes.length == 0)
19             throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
20
21         return new RROGeneralizedLabelSubobject(cutBytes, upStream);
22     }
23
24     @Override
25     public byte[] put(RROLabelSubobject objToSerialize) {
26         if (!(objToSerialize instanceof RROGeneralizedLabelSubobject))
27             throw new IllegalArgumentException("Unknown RROLabelSubobject instance. Passed " + objToSerialize.getClass()
28                     + ". Needed RROGeneralizedLabelSubobject.");
29         final byte[] retBytes = ((RROGeneralizedLabelSubobject) objToSerialize).getLabel();
30
31         return retBytes;
32     }
33
34 }