2 * Copyright (c) 2015 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
8 package org.opendaylight.protocol.rsvp.parser.spi.pojo;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.concepts.HandlerRegistry;
14 import org.opendaylight.protocol.rsvp.parser.spi.LabelParser;
15 import org.opendaylight.protocol.rsvp.parser.spi.LabelRegistry;
16 import org.opendaylight.protocol.rsvp.parser.spi.LabelSerializer;
17 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
18 import org.opendaylight.protocol.util.Values;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
20 import org.opendaylight.yangtools.concepts.Registration;
21 import org.opendaylight.yangtools.yang.binding.DataContainer;
23 public final class SimpleLabelRegistry implements LabelRegistry {
24 private final HandlerRegistry<DataContainer, LabelParser, LabelSerializer> handlers = new HandlerRegistry<>();
26 public Registration registerLabelParser(final int ctype, final LabelParser parser) {
27 checkArgument(ctype >= 0 && ctype <= Values.UNSIGNED_BYTE_MAX_VALUE);
28 return this.handlers.registerParser(ctype, parser);
31 public Registration registerLabelSerializer(final Class<? extends LabelType> labelClass,
32 final LabelSerializer serializer) {
33 return this.handlers.registerSerializer(labelClass, serializer);
37 public LabelType parseLabel(final int ctype, final ByteBuf buffer) throws RSVPParsingException {
38 checkArgument(ctype >= 0 && ctype <= Values.UNSIGNED_BYTE_MAX_VALUE);
39 final LabelParser parser = this.handlers.getParser(ctype);
43 return parser.parseLabel(buffer);
47 public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType label,
48 final ByteBuf buffer) {
49 final LabelSerializer serializer = this.handlers.getSerializer(label.getImplementedInterface());
50 if (serializer != null) {
51 serializer.serializeLabel(unidirectional, global, label, buffer);