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.branch.node.object.BranchNodeList;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.branch.node.object.BranchNodeListBuilder;
22 public final class BranchNodeListObjectParser extends AbstractEROWithSubobjectsParser {
24 private static final int CLASS = 31;
25 private static final int TYPE = 1;
27 public BranchNodeListObjectParser(final EROSubobjectRegistry subobjReg) {
28 super(subobjReg, CLASS, TYPE);
32 public BranchNodeList parseObject(final ObjectHeader header, final ByteBuf bytes)
33 throws PCEPDeserializerException {
34 Preconditions.checkArgument(bytes != null && bytes.isReadable(),
35 "Array of bytes is mandatory. Can't be null or empty.");
36 final BranchNodeListBuilder builder = new BranchNodeListBuilder();
37 builder.setIgnore(header.isIgnore());
38 builder.setProcessingRule(header.isProcessingRule());
39 builder.setSubobject(BNCUtil.toBncSubobject(parseSubobjects(bytes))).build();
40 return builder.build();
44 public void serializeObject(final Object object, final ByteBuf buffer) {
45 Preconditions.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.isProcessingRule(), object.isIgnore(), body, buffer);