*/
package org.opendaylight.protocol.pcep.spi.pojo;
+import com.google.common.base.Preconditions;
+
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.concepts.HandlerRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
import org.opendaylight.yangtools.yang.binding.DataContainer;
-import com.google.common.base.Preconditions;
-
/**
*
*/
public final class SimpleTlvRegistry implements TlvRegistry {
- private final HandlerRegistry<DataContainer, TlvParser, TlvSerializer> handlers = new HandlerRegistry<>();
-
- public AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) {
- Preconditions.checkArgument(tlvType >= 0 && tlvType < Values.UNSIGNED_SHORT_MAX_VALUE);
- return this.handlers.registerParser(tlvType, parser);
- }
-
- public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
- return this.handlers.registerSerializer(tlvClass, serializer);
- }
-
- @Override
- public Tlv parseTlv(final int type, final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE);
- final TlvParser parser = this.handlers.getParser(type);
- if (parser == null) {
- return null;
- }
- return parser.parseTlv(buffer);
- }
-
- @Override
- public byte[] serializeTlv(final Tlv tlv) {
- final TlvSerializer serializer = this.handlers.getSerializer(tlv.getImplementedInterface());
- if (serializer == null) {
- return null;
- }
- return serializer.serializeTlv(tlv);
- }
+ private final HandlerRegistry<DataContainer, TlvParser, TlvSerializer> handlers = new HandlerRegistry<>();
+
+ public AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) {
+ Preconditions.checkArgument(tlvType >= 0 && tlvType < Values.UNSIGNED_SHORT_MAX_VALUE);
+ return this.handlers.registerParser(tlvType, parser);
+ }
+
+ public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
+ return this.handlers.registerSerializer(tlvClass, serializer);
+ }
+
+ @Override
+ public Tlv parseTlv(final int type, final ByteBuf buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE);
+ final TlvParser parser = this.handlers.getParser(type);
+ if (parser == null) {
+ return null;
+ }
+ return parser.parseTlv(buffer);
+ }
+
+ @Override
+ public byte[] serializeTlv(final Tlv tlv) {
+ final TlvSerializer serializer = this.handlers.getSerializer(tlv.getImplementedInterface());
+ if (serializer == null) {
+ return null;
+ }
+ return serializer.serializeTlv(tlv);
+ }
}