2 * Copyright (c) 2018 AT&T Intellectual Property. 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.parser.object.bnc;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
15 import org.opendaylight.protocol.pcep.parser.object.AbstractEROWithSubobjectsParser;
16 import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
17 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.non.branch.node.object.NonBranchNodeList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.non.branch.node.object.NonBranchNodeListBuilder;
23 public final class NonBranchNodeListObjectParser extends AbstractEROWithSubobjectsParser {
24 private static final int CLASS = 31;
25 private static final int TYPE = 2;
27 public NonBranchNodeListObjectParser(final EROSubobjectRegistry subobjReg) {
28 super(subobjReg, CLASS, TYPE);
32 public NonBranchNodeList parseObject(final ObjectHeader header, final ByteBuf bytes)
33 throws PCEPDeserializerException {
34 checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
35 return new NonBranchNodeListBuilder()
36 .setIgnore(header.getIgnore())
37 .setProcessingRule(header.getProcessingRule())
38 .setSubobject(BNCUtil.toBncSubobject(parseSubobjects(bytes)))
43 public void serializeObject(final Object object, final ByteBuf buffer) {
44 checkArgument(object instanceof NonBranchNodeList,
45 "Wrong instance of PCEPObject. Passed %s. Needed NonBranchNodeList.", object.getClass());
46 final NonBranchNodeList nbnc = (NonBranchNodeList) object;
47 final ByteBuf body = Unpooled.buffer();
48 serializeSubobject(BNCUtil.toIroSubject(nbnc.getSubobject()), body);
49 ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);