Add ByteBufUtils.writeUint{8,16,32,64}
[yangtools.git] / yang / yang-common-netty / src / main / java / org / opendaylight / yangtools / yang / common / netty / ByteBufUtils.java
index 9569e40dd2eee82e03b2b44835bfee1ef099d2c9..7e087f90207601f256235d5aa295c5e21727feba 100644 (file)
@@ -94,7 +94,7 @@ public final class ByteBufUtils {
      * @param value A {@link Uint8}
      * @throws NullPointerException if any argument is null
      */
-    public static void write(final ByteBuf buf, final Uint8 value) {
+    public static void writeUint8(final ByteBuf buf, final Uint8 value) {
         buf.writeByte(value.byteValue());
     }
 
@@ -105,18 +105,18 @@ public final class ByteBufUtils {
      * @param value A {@link Uint16}
      * @throws NullPointerException if any argument is null
      */
-    public static void write(final ByteBuf buf, final Uint16 value) {
+    public static void writeUint16(final ByteBuf buf, final Uint16 value) {
         buf.writeShort(value.shortValue());
     }
 
     /**
-     * Write a {@link Uint32} from specified buffer.
+     * Write a {@link Uint32} to specified buffer.
      *
      * @param buf buffer
      * @param value A {@link Uint32}
      * @throws NullPointerException if any argument is null
      */
-    public static void write(final ByteBuf buf, final Uint32 value) {
+    public static void writeUint32(final ByteBuf buf, final Uint32 value) {
         buf.writeInt(value.intValue());
     }
 
@@ -127,10 +127,58 @@ public final class ByteBufUtils {
      * @param value A {@link Uint64}
      * @throws NullPointerException if any argument is null
      */
-    public static void write(final ByteBuf buf, final Uint64 value) {
+    public static void writeUint64(final ByteBuf buf, final Uint64 value) {
         buf.writeLong(value.longValue());
     }
 
+    /**
+     * Write a {@link Uint8} to specified buffer. This method is provided for convenience, you may want to use
+     * {@link #writeUint8(ByteBuf, Uint8)} as it is more explicit.
+     *
+     * @param buf buffer
+     * @param value A {@link Uint8}
+     * @throws NullPointerException if any argument is null
+     */
+    public static void write(final ByteBuf buf, final Uint8 value) {
+        writeUint8(buf, value);
+    }
+
+    /**
+     * Write a {@link Uint16} to specified buffer. This method is provided for convenience, you may want to use
+     * {@link #writeUint16(ByteBuf, Uint16)} as it is more explicit.
+     *
+     * @param buf buffer
+     * @param value A {@link Uint16}
+     * @throws NullPointerException if any argument is null
+     */
+    public static void write(final ByteBuf buf, final Uint16 value) {
+        writeUint16(buf, value);
+    }
+
+    /**
+     * Write a {@link Uint32} to specified buffer. This method is provided for convenience, you may want to use
+     * {@link #writeUint32(ByteBuf, Uint32)} as it is more explicit.
+     *
+     * @param buf buffer
+     * @param value A {@link Uint32}
+     * @throws NullPointerException if any argument is null
+     */
+    public static void write(final ByteBuf buf, final Uint32 value) {
+        writeUint32(buf, value);
+    }
+
+    /**
+     * Write a {@link Uint64} to specified buffer. This method is provided for convenience, you may want to use
+     * {@link #writeUint64(ByteBuf, Uint64)} as it is more explicit.
+     *
+     * @param buf buffer
+     * @param value A {@link Uint64}
+     * @throws NullPointerException if any argument is null
+     */
+    public static void write(final ByteBuf buf, final Uint64 value) {
+        writeUint64(buf, value);
+    }
+
     /**
      * Write a {@link Byte} property to specified buffer. If the {@code value} is known to be non-null, prefer
      * {@link ByteBuf#writeByte(int)} instead of this method.
@@ -170,7 +218,7 @@ public final class ByteBufUtils {
      * @throws IllegalArgumentException if {@code value} is null
      */
     public static void writeMandatory(final ByteBuf buf, final Integer value, final String name) {
-        buf.writeInt(nonNullArgument(value, name).intValue());
+        buf.writeInt(nonNullArgument(value, name));
     }
 
     /**
@@ -184,7 +232,7 @@ public final class ByteBufUtils {
      * @throws IllegalArgumentException if {@code value} is null
      */
     public static void writeMandatory(final ByteBuf buf, final Long value, final String name) {
-        buf.writeLong(nonNullArgument(value, name).longValue());
+        buf.writeLong(nonNullArgument(value, name));
     }
 
     /**
@@ -278,7 +326,7 @@ public final class ByteBufUtils {
      */
     public static void writeOptional(final ByteBuf buf, final @Nullable Integer value) {
         if (value != null) {
-            buf.writeInt(value.intValue());
+            buf.writeInt(value);
         }
     }
 
@@ -291,7 +339,7 @@ public final class ByteBufUtils {
      */
     public static void writeOptional(final ByteBuf buf, final @Nullable Long value) {
         if (value != null) {
-            buf.writeLong(value.longValue());
+            buf.writeLong(value);
         }
     }
 
@@ -359,10 +407,10 @@ public final class ByteBufUtils {
     }
 
     /**
-     * Write a {@link Byte} value to specified buffer if it is not null, otherwise write two zero bytes.
+     * Write a {@link Short} value to specified buffer if it is not null, otherwise write two zero bytes.
      *
      * @param buf buffer
-     * @param value A {@link Byte}
+     * @param value A {@link Short}
      * @throws NullPointerException if {@code buf} is null
      */
     public static void writeOrZero(final ByteBuf buf, final @Nullable Short value) {
@@ -370,14 +418,14 @@ public final class ByteBufUtils {
     }
 
     /**
-     * Write a {@link Byte} value to specified buffer if it is not null, otherwise write four zero bytes.
+     * Write a {@link Integer} value to specified buffer if it is not null, otherwise write four zero bytes.
      *
      * @param buf buffer
-     * @param value A {@link Byte}
+     * @param value A {@link Integer}
      * @throws NullPointerException if {@code buf} is null
      */
     public static void writeOrZero(final ByteBuf buf, final @Nullable Integer value) {
-        buf.writeInt(value != null ? value.intValue() : 0);
+        buf.writeInt(value != null ? value : 0);
     }
 
     /**
@@ -388,14 +436,14 @@ public final class ByteBufUtils {
      * @throws NullPointerException if {@code buf} is null
      */
     public static void writeOrZero(final ByteBuf buf, final @Nullable Long value) {
-        buf.writeLong(value != null ? value.longValue() : 0L);
+        buf.writeLong(value != null ? value : 0L);
     }
 
     /**
-     * Write a {@link Byte} value to specified buffer if it is not null, otherwise write one zero byte.
+     * Write a {@link Uint8} value to specified buffer if it is not null, otherwise write one zero byte.
      *
      * @param buf buffer
-     * @param value A {@link Byte}
+     * @param value A {@link Uint8}
      * @throws NullPointerException if {@code buf} is null
      */
     public static void writeOrZero(final ByteBuf buf, final @Nullable Uint8 value) {
@@ -403,10 +451,10 @@ public final class ByteBufUtils {
     }
 
     /**
-     * Write a {@link Byte} value to specified buffer if it is not null, otherwise write two zero bytes.
+     * Write a {@link Uint16} value to specified buffer if it is not null, otherwise write two zero bytes.
      *
      * @param buf buffer
-     * @param value A {@link Byte}
+     * @param value A {@link Uint16}
      * @throws NullPointerException if {@code buf} is null
      */
     public static void writeOrZero(final ByteBuf buf, final @Nullable Uint16 value) {
@@ -414,10 +462,10 @@ public final class ByteBufUtils {
     }
 
     /**
-     * Write a {@link Byte} value to specified buffer if it is not null, otherwise write four zero bytes.
+     * Write a {@link Uint32} value to specified buffer if it is not null, otherwise write four zero bytes.
      *
      * @param buf buffer
-     * @param value A {@link Byte}
+     * @param value A {@link Uint32}
      * @throws NullPointerException if {@code buf} is null
      */
     public static void writeOrZero(final ByteBuf buf, final @Nullable Uint32 value) {
@@ -425,10 +473,10 @@ public final class ByteBufUtils {
     }
 
     /**
-     * Write a {@link Byte} value to specified buffer if it is not null, otherwise write eight zero bytes.
+     * Write a {@link Uint64} value to specified buffer if it is not null, otherwise write eight zero bytes.
      *
      * @param buf buffer
-     * @param value A {@link Byte}
+     * @param value A {@link Uint64}
      * @throws NullPointerException if {@code buf} is null
      */
     public static void writeOrZero(final ByteBuf buf, final @Nullable Uint64 value) {