Java tutorial
/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.protocol.bmp.impl.tlv; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException; import org.opendaylight.protocol.bmp.spi.parser.BmpTlvParser; import org.opendaylight.protocol.bmp.spi.parser.BmpTlvSerializer; import org.opendaylight.protocol.bmp.spi.parser.TlvUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.Reason; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.Tlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.reason.tlv.ReasonTlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.reason.tlv.ReasonTlvBuilder; public class ReasonTlvHandler implements BmpTlvParser, BmpTlvSerializer { public static final int TYPE = 1; @Override public void serializeTlv(final Tlv tlv, final ByteBuf output) { Preconditions.checkArgument(tlv instanceof ReasonTlv, "ReasonTlv is mandatory."); TlvUtil.formatTlv(TYPE, Unpooled.copyShort(((ReasonTlv) tlv).getReason().getIntValue()), output); } @Override public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException { if (buffer == null) { return null; } return new ReasonTlvBuilder().setReason(Reason.forValue(buffer.readUnsignedShort())).build(); } }