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 com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.opendaylight.protocol.pcep.parser.object.AbstractEROWithSubobjectsParser;
14 import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
15 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
16 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.non.branch.node.object.NonBranchNodeList;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.non.branch.node.object.NonBranchNodeListBuilder;
22 public final class NonBranchNodeListObjectParser extends AbstractEROWithSubobjectsParser {
23 private static final int CLASS = 31;
24 private static final int TYPE = 2;
26 public NonBranchNodeListObjectParser(final EROSubobjectRegistry subobjReg) {
27 super(subobjReg, CLASS, TYPE);
31 public NonBranchNodeList parseObject(final ObjectHeader header, final ByteBuf bytes)
32 throws PCEPDeserializerException {
33 Preconditions.checkArgument(bytes != null && bytes.isReadable(),
34 "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 Preconditions.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);