2 * Copyright (c) 2014 Cisco Systems, Inc. and others. 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
9 package org.opendaylight.protocol.pcep.spi.pojo;
11 import com.google.common.primitives.Ints;
12 import io.netty.buffer.ByteBuf;
13 import java.util.Optional;
14 import org.opendaylight.protocol.concepts.HandlerRegistry;
15 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
16 import org.opendaylight.protocol.pcep.spi.TlvParser;
17 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
18 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.EnterpriseSpecificInformation;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv;
22 import org.opendaylight.yangtools.yang.binding.DataContainer;
24 public class SimpleVendorInformationTlvRegistry implements VendorInformationTlvRegistry {
26 private final HandlerRegistry<DataContainer, TlvParser, TlvSerializer> handlers = new HandlerRegistry<>();
28 public AutoCloseable registerVendorInformationTlvParser(final EnterpriseNumber enterpriseNumber, final TlvParser parser) {
29 return this.handlers.registerParser(Ints.checkedCast(enterpriseNumber.getValue()), parser);
32 public AutoCloseable registerVendorInformationTlvSerializer(final Class<? extends EnterpriseSpecificInformation> esInformationClass, final TlvSerializer serializer) {
33 return this.handlers.registerSerializer(esInformationClass, serializer);
37 public Optional<VendorInformationTlv> parseVendorInformationTlv(final EnterpriseNumber enterpriseNumber, final ByteBuf buffer) throws PCEPDeserializerException {
38 final TlvParser parser = this.handlers.getParser(Ints.checkedCast(enterpriseNumber.getValue()));
40 return Optional.empty();
42 return Optional.of((VendorInformationTlv) parser.parseTlv(buffer));
46 public void serializeVendorInformationTlv(final VendorInformationTlv viTlv, final ByteBuf buffer) {
47 final TlvSerializer serializer = this.handlers.getSerializer(viTlv.getEnterpriseSpecificInformation().getImplementedInterface());
48 if (serializer == null) {
51 serializer.serializeTlv(viTlv, buffer);