/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.protocol.pcep.impl.subobject; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.LabelParser; import org.opendaylight.protocol.pcep.spi.LabelSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.GeneralizedLabel; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelBuilder; /** * Parser for {@link GeneralizedLabel} */ public class GeneralizedLabelParser implements LabelParser, LabelSerializer { public static final int CTYPE = 2; @Override public LabelType parseLabel(final byte[] buffer) throws PCEPDeserializerException { if (buffer == null || buffer.length == 0) { throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); } return new GeneralizedLabelBuilder().setGeneralizedLabel(buffer).build(); } @Override public byte[] serializeLabel(final CLabel subobject) { if (!(subobject instanceof GeneralizedLabel)) { throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass() + ". Needed GeneralizedLabel."); } return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabel) subobject).getGeneralizedLabel(); } @Override public int getType() { return CTYPE; } }