Class ByteBufUtils
- java.lang.Object
-
- org.opendaylight.yangtools.yang.common.netty.ByteBufUtils
-
@Beta public final class ByteBufUtils extends Object
Utility methods for interacting withByteBufs. These add a number of methods for reading and writing various data types from/to ByteBufs. Methods fall into these categories:readUint*, which extract the corresponding amount of data from a buffer and return an Uint type. These are more efficient than going theUint8.valueOf(buf.readUnsignedByte())route.writeUint*, which write specified value into a buffer.writeMandatory*, which write a property not statically known to be non-null. These methods throw anIllegalArgumentExceptionif the supplied value is null. Otherwise they will write it to provided buffer.writeOptional*, which write a value which can legally be null. In case the value is not null, it is written to the provided buffer. If the value null, the method does nothing.writeOrZero*, which write a value which can legally be null. In case the value is not null, it is written to the provided buffer. If the value is null, a {code zero} value of corresponding width is written instead.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @NonNull org.opendaylight.yangtools.yang.common.Uint16readUint16(io.netty.buffer.ByteBuf buf)Read aUint16from specified buffer.static @NonNull org.opendaylight.yangtools.yang.common.Uint32readUint32(io.netty.buffer.ByteBuf buf)Read aUint32from specified buffer.static @NonNull org.opendaylight.yangtools.yang.common.Uint64readUint64(io.netty.buffer.ByteBuf buf)Read aUint64from specified buffer.static @NonNull org.opendaylight.yangtools.yang.common.Uint8readUint8(io.netty.buffer.ByteBuf buf)Read anUint8from specified buffer.static voidwrite(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint16 value)Write aUint16to specified buffer.static voidwrite(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint32 value)Write aUint32to specified buffer.static voidwrite(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint64 value)Write aUint64to specified buffer.static voidwrite(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint8 value)Write aUint8to specified buffer.static voidwriteMandatory(io.netty.buffer.ByteBuf buf, Byte value, String name)Write aByteproperty to specified buffer.static voidwriteMandatory(io.netty.buffer.ByteBuf buf, Integer value, String name)Write aIntegerproperty to specified buffer.static voidwriteMandatory(io.netty.buffer.ByteBuf buf, Long value, String name)Write aLongproperty to specified buffer.static voidwriteMandatory(io.netty.buffer.ByteBuf buf, Short value, String name)Write aShortproperty to specified buffer.static voidwriteMandatory(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint16 value, String name)Write aUint16property to specified buffer.static voidwriteMandatory(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint32 value, String name)Write aUint32property to specified buffer.static voidwriteMandatory(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint64 value, String name)Write aUint64property to specified buffer.static voidwriteMandatory(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint8 value, String name)Write aUint8property to specified buffer.static voidwriteOptional(io.netty.buffer.ByteBuf buf, @Nullable Byte value)Write aBytevalue to specified buffer if it is not null.static voidwriteOptional(io.netty.buffer.ByteBuf buf, @Nullable Integer value)Write aIntegervalue to specified buffer if it is not null.static voidwriteOptional(io.netty.buffer.ByteBuf buf, @Nullable Long value)Write aLongvalue to specified buffer if it is not null.static voidwriteOptional(io.netty.buffer.ByteBuf buf, @Nullable Short value)Write aBytevalue to specified buffer if it is not null.static voidwriteOptional(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint16 value)Write aUint16value to specified buffer if it is not null.static voidwriteOptional(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint32 value)Write aUint32value to specified buffer if it is not null.static voidwriteOptional(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint64 value)Write aUint64value to specified buffer if it is not null.static voidwriteOptional(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint8 value)Write aUint8value to specified buffer if it is not null.static voidwriteOrZero(io.netty.buffer.ByteBuf buf, @Nullable Byte value)Write aBytevalue to specified buffer if it is not null, otherwise write one zero byte.static voidwriteOrZero(io.netty.buffer.ByteBuf buf, @Nullable Integer value)Write aIntegervalue to specified buffer if it is not null, otherwise write four zero bytes.static voidwriteOrZero(io.netty.buffer.ByteBuf buf, @Nullable Long value)Write aBytevalue to specified buffer if it is not null, otherwise write eight zero bytes.static voidwriteOrZero(io.netty.buffer.ByteBuf buf, @Nullable Short value)Write aShortvalue to specified buffer if it is not null, otherwise write two zero bytes.static voidwriteOrZero(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint16 value)Write aUint16value to specified buffer if it is not null, otherwise write two zero bytes.static voidwriteOrZero(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint32 value)Write aUint32value to specified buffer if it is not null, otherwise write four zero bytes.static voidwriteOrZero(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint64 value)Write aUint64value to specified buffer if it is not null, otherwise write eight zero bytes.static voidwriteOrZero(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint8 value)Write aUint8value to specified buffer if it is not null, otherwise write one zero byte.static voidwriteUint16(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint16 value)Write aUint16to specified buffer.static voidwriteUint32(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint32 value)Write aUint32to specified buffer.static voidwriteUint64(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint64 value)Write aUint64to specified buffer.static voidwriteUint8(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint8 value)Write aUint8to specified buffer.
-
-
-
Method Detail
-
readUint8
public static @NonNull org.opendaylight.yangtools.yang.common.Uint8 readUint8(io.netty.buffer.ByteBuf buf)
Read anUint8from specified buffer.- Parameters:
buf- buffer- Returns:
- A
Uint8 - Throws:
NullPointerException- ifbufis nullIndexOutOfBoundsException- ifbufdoes not have enough data
-
readUint16
public static @NonNull org.opendaylight.yangtools.yang.common.Uint16 readUint16(io.netty.buffer.ByteBuf buf)
Read aUint16from specified buffer.- Parameters:
buf- buffer- Returns:
- A
Uint16 - Throws:
NullPointerException- ifbufis nullIndexOutOfBoundsException- ifbufdoes not have enough data
-
readUint32
public static @NonNull org.opendaylight.yangtools.yang.common.Uint32 readUint32(io.netty.buffer.ByteBuf buf)
Read aUint32from specified buffer.- Parameters:
buf- buffer- Returns:
- A
Uint32 - Throws:
NullPointerException- ifbufis nullIndexOutOfBoundsException- ifbufdoes not have enough data
-
readUint64
public static @NonNull org.opendaylight.yangtools.yang.common.Uint64 readUint64(io.netty.buffer.ByteBuf buf)
Read aUint64from specified buffer.- Parameters:
buf- buffer- Returns:
- A
Uint64 - Throws:
NullPointerException- ifbufis nullIndexOutOfBoundsException- ifbufdoes not have enough data
-
writeUint8
public static void writeUint8(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint8 value)Write aUint8to specified buffer.- Parameters:
buf- buffervalue- AUint8- Throws:
NullPointerException- if any argument is null
-
writeUint16
public static void writeUint16(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint16 value)Write aUint16to specified buffer.- Parameters:
buf- buffervalue- AUint16- Throws:
NullPointerException- if any argument is null
-
writeUint32
public static void writeUint32(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint32 value)Write aUint32to specified buffer.- Parameters:
buf- buffervalue- AUint32- Throws:
NullPointerException- if any argument is null
-
writeUint64
public static void writeUint64(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint64 value)Write aUint64to specified buffer.- Parameters:
buf- buffervalue- AUint64- Throws:
NullPointerException- if any argument is null
-
write
public static void write(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint8 value)Write aUint8to specified buffer. This method is provided for convenience, you may want to usewriteUint8(ByteBuf, Uint8)as it is more explicit.- Parameters:
buf- buffervalue- AUint8- Throws:
NullPointerException- if any argument is null
-
write
public static void write(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint16 value)Write aUint16to specified buffer. This method is provided for convenience, you may want to usewriteUint16(ByteBuf, Uint16)as it is more explicit.- Parameters:
buf- buffervalue- AUint16- Throws:
NullPointerException- if any argument is null
-
write
public static void write(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint32 value)Write aUint32to specified buffer. This method is provided for convenience, you may want to usewriteUint32(ByteBuf, Uint32)as it is more explicit.- Parameters:
buf- buffervalue- AUint32- Throws:
NullPointerException- if any argument is null
-
write
public static void write(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint64 value)Write aUint64to specified buffer. This method is provided for convenience, you may want to usewriteUint64(ByteBuf, Uint64)as it is more explicit.- Parameters:
buf- buffervalue- AUint64- Throws:
NullPointerException- if any argument is null
-
writeMandatory
public static void writeMandatory(io.netty.buffer.ByteBuf buf, Byte value, String name)Write aByteproperty to specified buffer. If thevalueis known to be non-null, preferByteBuf.writeByte(int)instead of this method.- Parameters:
buf- buffervalue- ABytename- Property name for error reporting purposes- Throws:
NullPointerException- ifbufis nullIllegalArgumentException- ifvalueis null
-
writeMandatory
public static void writeMandatory(io.netty.buffer.ByteBuf buf, Short value, String name)Write aShortproperty to specified buffer. If thevalueis known to be non-null, preferByteBuf.writeShort(int)instead of this method.- Parameters:
buf- buffervalue- AShortname- Property name for error reporting purposes- Throws:
NullPointerException- ifbufis nullIllegalArgumentException- ifvalueis null
-
writeMandatory
public static void writeMandatory(io.netty.buffer.ByteBuf buf, Integer value, String name)Write aIntegerproperty to specified buffer. If thevalueis known to be non-null, preferByteBuf.writeInt(int)instead of this method.- Parameters:
buf- buffervalue- AIntegername- Property name for error reporting purposes- Throws:
NullPointerException- ifbufis nullIllegalArgumentException- ifvalueis null
-
writeMandatory
public static void writeMandatory(io.netty.buffer.ByteBuf buf, Long value, String name)Write aLongproperty to specified buffer. If thevalueis known to be non-null, preferByteBuf.writeLong(long)instead of this method.- Parameters:
buf- buffervalue- ALongname- Property name for error reporting purposes- Throws:
NullPointerException- ifbufis nullIllegalArgumentException- ifvalueis null
-
writeMandatory
public static void writeMandatory(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint8 value, String name)Write aUint8property to specified buffer. If thevalueis known to be non-null, prefer to usewrite(ByteBuf, Uint8)instead of this method.- Parameters:
buf- buffervalue- AUint8name- Property name for error reporting purposes- Throws:
NullPointerException- ifbufis nullIllegalArgumentException- ifvalueis null
-
writeMandatory
public static void writeMandatory(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint16 value, String name)Write aUint16property to specified buffer. If thevalueis known to be non-null, prefer to usewrite(ByteBuf, Uint16)instead of this method.- Parameters:
buf- buffervalue- AUint16name- Property name for error reporting purposes- Throws:
NullPointerException- ifbufis nullIllegalArgumentException- ifvalueis null
-
writeMandatory
public static void writeMandatory(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint32 value, String name)Write aUint32property to specified buffer. If thevalueis known to be non-null, prefer to usewrite(ByteBuf, Uint32)instead of this method.- Parameters:
buf- buffervalue- AUint32name- Property name for error reporting purposes- Throws:
NullPointerException- ifbufis nullIllegalArgumentException- ifvalueis null
-
writeMandatory
public static void writeMandatory(io.netty.buffer.ByteBuf buf, org.opendaylight.yangtools.yang.common.Uint64 value, String name)Write aUint64property to specified buffer. If thevalueis known to be non-null, prefer to usewrite(ByteBuf, Uint64)instead of this method.- Parameters:
buf- buffervalue- AUint64name- Property name for error reporting purposes- Throws:
NullPointerException- ifbufis nullIllegalArgumentException- ifvalueis null
-
writeOptional
public static void writeOptional(io.netty.buffer.ByteBuf buf, @Nullable Byte value)Write aBytevalue to specified buffer if it is not null.- Parameters:
buf- buffervalue- AByte- Throws:
NullPointerException- ifbufis null
-
writeOptional
public static void writeOptional(io.netty.buffer.ByteBuf buf, @Nullable Short value)Write aBytevalue to specified buffer if it is not null.- Parameters:
buf- buffervalue- AShort- Throws:
NullPointerException- ifbufis null
-
writeOptional
public static void writeOptional(io.netty.buffer.ByteBuf buf, @Nullable Integer value)Write aIntegervalue to specified buffer if it is not null.- Parameters:
buf- buffervalue- AInteger- Throws:
NullPointerException- ifbufis null
-
writeOptional
public static void writeOptional(io.netty.buffer.ByteBuf buf, @Nullable Long value)Write aLongvalue to specified buffer if it is not null.- Parameters:
buf- buffervalue- ALong- Throws:
NullPointerException- ifbufis null
-
writeOptional
public static void writeOptional(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint8 value)Write aUint8value to specified buffer if it is not null.- Parameters:
buf- buffervalue- AUint8- Throws:
NullPointerException- ifbufis null
-
writeOptional
public static void writeOptional(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint16 value)Write aUint16value to specified buffer if it is not null.- Parameters:
buf- buffervalue- AUint16- Throws:
NullPointerException- ifbufis null
-
writeOptional
public static void writeOptional(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint32 value)Write aUint32value to specified buffer if it is not null.- Parameters:
buf- buffervalue- AUint32- Throws:
NullPointerException- ifbufis null
-
writeOptional
public static void writeOptional(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint64 value)Write aUint64value to specified buffer if it is not null.- Parameters:
buf- buffervalue- AUint64- Throws:
NullPointerException- ifbufis null
-
writeOrZero
public static void writeOrZero(io.netty.buffer.ByteBuf buf, @Nullable Byte value)Write aBytevalue to specified buffer if it is not null, otherwise write one zero byte.- Parameters:
buf- buffervalue- AByte- Throws:
NullPointerException- ifbufis null
-
writeOrZero
public static void writeOrZero(io.netty.buffer.ByteBuf buf, @Nullable Short value)Write aShortvalue to specified buffer if it is not null, otherwise write two zero bytes.- Parameters:
buf- buffervalue- AShort- Throws:
NullPointerException- ifbufis null
-
writeOrZero
public static void writeOrZero(io.netty.buffer.ByteBuf buf, @Nullable Integer value)Write aIntegervalue to specified buffer if it is not null, otherwise write four zero bytes.- Parameters:
buf- buffervalue- AInteger- Throws:
NullPointerException- ifbufis null
-
writeOrZero
public static void writeOrZero(io.netty.buffer.ByteBuf buf, @Nullable Long value)Write aBytevalue to specified buffer if it is not null, otherwise write eight zero bytes.- Parameters:
buf- buffervalue- AByte- Throws:
NullPointerException- ifbufis null
-
writeOrZero
public static void writeOrZero(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint8 value)Write aUint8value to specified buffer if it is not null, otherwise write one zero byte.- Parameters:
buf- buffervalue- AUint8- Throws:
NullPointerException- ifbufis null
-
writeOrZero
public static void writeOrZero(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint16 value)Write aUint16value to specified buffer if it is not null, otherwise write two zero bytes.- Parameters:
buf- buffervalue- AUint16- Throws:
NullPointerException- ifbufis null
-
writeOrZero
public static void writeOrZero(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint32 value)Write aUint32value to specified buffer if it is not null, otherwise write four zero bytes.- Parameters:
buf- buffervalue- AUint32- Throws:
NullPointerException- ifbufis null
-
writeOrZero
public static void writeOrZero(io.netty.buffer.ByteBuf buf, @Nullable org.opendaylight.yangtools.yang.common.Uint64 value)Write aUint64value to specified buffer if it is not null, otherwise write eight zero bytes.- Parameters:
buf- buffervalue- AUint64- Throws:
NullPointerException- ifbufis null
-
-