Move ipv4/ipv6 ByteBuf utilities to Ipv{4,6}Util
[bgpcep.git] / util / src / main / java / org / opendaylight / protocol / util / ByteBufWriteUtil.java
1 /*
2  * Copyright (c) 2014 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.util;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
12
13 /**
14  * Utility class for ByteBuf's write methods.
15  */
16 public final class ByteBufWriteUtil {
17     private ByteBufWriteUtil() {
18         // Hidden on purpose
19     }
20
21     /**
22      * Writes Float32 <code>value</code> if not null, otherwise writes zeros to
23      * the <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
24      *
25      * @param value
26      *            Float32 value to be written to the output.
27      * @param output
28      *            ByteBuf, where value or zeros are written.
29      */
30     public static void writeFloat32(final Float32 value, final ByteBuf output) {
31         if (value != null) {
32             output.writeBytes(value.getValue());
33         } else {
34             output.writeInt(0);
35         }
36     }
37 }