Do not rely on deprecated classes directly
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / BGPMessageFactoryImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.parser.impl;
9
10 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
11 import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
12 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
13 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
14 import org.opendaylight.yangtools.yang.binding.Notification;
15
16 import com.google.common.base.Preconditions;
17
18 public final class BGPMessageFactoryImpl implements BGPMessageFactory {
19         private final MessageRegistry registry;
20
21         public BGPMessageFactoryImpl(final MessageRegistry registry) {
22                 this.registry = Preconditions.checkNotNull(registry);
23         }
24
25         /*
26          * (non-Javadoc)
27          * @see org.opendaylight.protocol.bgp.parser.BGPMessageParser#parse(byte[])
28          */
29         @Override
30         public Notification parse(final byte[] bytes) throws BGPParsingException, BGPDocumentedException {
31                 return this.registry.parseMessage(bytes);
32         }
33
34         @Override
35         public byte[] put(final Notification msg) {
36                 return this.registry.serializeMessage(msg);
37         }
38 }