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.subobject;
10 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.pcep.spi.LabelParser;
13 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
14 import org.opendaylight.protocol.pcep.spi.LabelUtil;
15 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
16 import org.opendaylight.protocol.util.ByteArray;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.generalized.label._case.GeneralizedLabelBuilder;
22 import com.google.common.base.Preconditions;
25 * Parser for {@link GeneralizedLabelCase}
27 public class GeneralizedLabelParser implements LabelParser, LabelSerializer {
29 public static final int CTYPE = 2;
32 public LabelType parseLabel(final ByteBuf buffer) throws PCEPDeserializerException {
33 Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
34 return new GeneralizedLabelCaseBuilder().setGeneralizedLabel(new GeneralizedLabelBuilder().setGeneralizedLabel(ByteArray.readAllBytes(buffer)).build()).build();
38 public byte[] serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject) {
39 if (!(subobject instanceof GeneralizedLabelCase)) {
40 throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass()
41 + ". Needed GeneralizedLabelCase.");
43 return LabelUtil.formatLabel(CTYPE, unidirectional, global, ((GeneralizedLabelCase) subobject).getGeneralizedLabel().getGeneralizedLabel());