YANG revision dates mass-update
[bgpcep.git] / bmp / bmp-parser-impl / src / main / java / org / opendaylight / protocol / bmp / parser / tlv / StringTlvHandler.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.protocol.bmp.parser.tlv;
10
11 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import java.nio.charset.StandardCharsets;
14 import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
15 import org.opendaylight.protocol.bmp.spi.parser.BmpTlvParser;
16 import org.opendaylight.protocol.bmp.spi.parser.BmpTlvSerializer;
17 import org.opendaylight.protocol.bmp.spi.parser.TlvUtil;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Tlv;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.string.tlv.StringTlv;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.string.tlv.StringTlvBuilder;
21
22 public class StringTlvHandler implements BmpTlvParser, BmpTlvSerializer {
23
24     public static final int TYPE = 0;
25
26     @Override
27     public void serializeTlv(final Tlv tlv, final ByteBuf output) {
28         Preconditions.checkArgument(tlv instanceof StringTlv, "StringTlv is mandatory.");
29         TlvUtil.formatTlvUtf8(TYPE, ((StringTlv) tlv).getStringInfo(), output);
30     }
31
32     @Override
33     public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException {
34         if (buffer == null) {
35             return null;
36         }
37         return new StringTlvBuilder().setStringInfo(buffer.toString(StandardCharsets.UTF_8)).build();
38     }
39
40 }