d3acad146b7e4b782a142296b82f5c87422984e7
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / subobject / EROAsNumberSubobjectParser.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.parser.subobject;
9
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
13 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
14 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
15 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
19
20 /**
21  * Parser for {@link AsNumberCase}.
22  */
23 public class EROAsNumberSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
24
25     public static final int TYPE = 32;
26
27     @Override
28     public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
29         return new SubobjectBuilder().setLoose(loose).setSubobjectType(AsNumberCaseParser.parseSubobject(buffer))
30                 .build();
31     }
32
33     @Override
34     public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
35         Preconditions.checkArgument(subobject.getSubobjectType() instanceof AsNumberCase,
36                 "Unknown subobject instance. Passed %s. Needed AsNumberCase.", subobject.getSubobjectType().getClass());
37         final ByteBuf body = AsNumberCaseParser.serializeSubobject((AsNumberCase) subobject.getSubobjectType());
38         EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
39     }
40 }