2 * Copyright (c) 2013 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.bgp.parser.spi.pojo;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
14 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
15 import org.opendaylight.protocol.bgp.parser.spi.ParameterParser;
16 import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
17 import org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer;
18 import org.opendaylight.protocol.concepts.HandlerRegistry;
19 import org.opendaylight.protocol.util.Values;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.BgpParameters;
21 import org.opendaylight.yangtools.concepts.Registration;
22 import org.opendaylight.yangtools.yang.binding.DataContainer;
24 final class SimpleParameterRegistry implements ParameterRegistry {
25 private final HandlerRegistry<DataContainer, ParameterParser, ParameterSerializer> handlers =
26 new HandlerRegistry<>();
28 Registration registerParameterParser(final int messageType, final ParameterParser parser) {
29 // 255 is explicitly excluded because it is handled in OPEN message parser
30 checkArgument(messageType >= 0 && messageType < Values.UNSIGNED_BYTE_MAX_VALUE);
31 return this.handlers.registerParser(messageType, parser);
34 Registration registerParameterSerializer(final Class<? extends BgpParameters> paramClass,
35 final ParameterSerializer serializer) {
36 return this.handlers.registerSerializer(paramClass, serializer);
40 public BgpParameters parseParameter(final int parameterType, final ByteBuf buffer) throws BGPParsingException,
41 BGPDocumentedException {
42 final ParameterParser parser = this.handlers.getParser(parameterType);
46 return parser.parseParameter(buffer);
50 public void serializeParameter(final BgpParameters parameter, final ByteBuf bytes) {
51 final ParameterSerializer serializer = this.handlers.getSerializer(parameter.implementedInterface());
52 if (serializer == null) {
55 serializer.serializeParameter(parameter,bytes);