Enable restart of CSS modules on blueprint container restart
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / subobject / GeneralizedLabelParser.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 com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.opendaylight.protocol.pcep.spi.LabelParser;
14 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
15 import org.opendaylight.protocol.pcep.spi.LabelUtil;
16 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
17 import org.opendaylight.protocol.util.ByteArray;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.GeneralizedLabelCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.GeneralizedLabelCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.generalized.label._case.GeneralizedLabel;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.generalized.label._case.GeneralizedLabelBuilder;
23
24 /**
25  * Parser for {@link GeneralizedLabelCase}
26  */
27 public class GeneralizedLabelParser implements LabelParser, LabelSerializer {
28
29     public static final int CTYPE = 2;
30
31     @Override
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(
35                 new GeneralizedLabelBuilder().setGeneralizedLabel(ByteArray.readAllBytes(buffer)).build()).build();
36     }
37
38     @Override
39     public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) {
40         Preconditions.checkArgument(subobject instanceof GeneralizedLabelCase, "Unknown Label Subobject instance. Passed {}. Needed GeneralizedLabelCase.", subobject.getClass());
41         final GeneralizedLabel gl = ((GeneralizedLabelCase) subobject).getGeneralizedLabel();
42         Preconditions.checkArgument(gl != null, "GeneralizedLabel is mandatory.");
43         final ByteBuf body = Unpooled.wrappedBuffer(gl.getGeneralizedLabel());
44         LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
45     }
46 }