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.branch.node.object.BranchNodeList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.branch.node.object.BranchNodeListBuilder;
23 public final class BranchNodeListObjectParser extends AbstractEROWithSubobjectsParser {
25 private static final int CLASS = 31;
26 private static final int TYPE = 1;
28 public BranchNodeListObjectParser(final EROSubobjectRegistry subobjReg) {
29 super(subobjReg, CLASS, TYPE);
33 public BranchNodeList parseObject(final ObjectHeader header, final ByteBuf bytes)
34 throws PCEPDeserializerException {
35 checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
36 return new BranchNodeListBuilder()
37 .setIgnore(header.getIgnore())
38 .setProcessingRule(header.getProcessingRule())
39 .setSubobject(BNCUtil.toBncSubobject(parseSubobjects(bytes)))
44 public void serializeObject(final Object object, final ByteBuf buffer) {
45 checkArgument(object instanceof BranchNodeList,
46 "Wrong instance of PCEPObject. Passed %s. Needed BranchNodeList.", object.getClass());
47 final BranchNodeList nbnc = (BranchNodeList) object;
48 final ByteBuf body = Unpooled.buffer();
49 serializeSubobject(BNCUtil.toIroSubject(nbnc.getSubobject()), body);
50 ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);