Class ByteBufUtils
java.lang.Object
org.opendaylight.yangtools.yang.common.netty.ByteBufUtils
Utility methods for interacting with
ByteBuf
s. 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 anIllegalArgumentException
if 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
Modifier and TypeMethodDescriptionstatic @NonNull Uint16
readUint16
(io.netty.buffer.ByteBuf buf) Read aUint16
from specified buffer.static @NonNull Uint32
readUint32
(io.netty.buffer.ByteBuf buf) Read aUint32
from specified buffer.static @NonNull Uint64
readUint64
(io.netty.buffer.ByteBuf buf) Read aUint64
from specified buffer.static @NonNull Uint8
readUint8
(io.netty.buffer.ByteBuf buf) Read anUint8
from specified buffer.static void
Write aUint16
to specified buffer.static void
Write aUint32
to specified buffer.static void
Write aUint64
to specified buffer.static void
Write aUint8
to specified buffer.static void
writeMandatory
(io.netty.buffer.ByteBuf buf, Byte value, String name) Write aByte
property to specified buffer.static void
writeMandatory
(io.netty.buffer.ByteBuf buf, Integer value, String name) Write aInteger
property to specified buffer.static void
writeMandatory
(io.netty.buffer.ByteBuf buf, Long value, String name) Write aLong
property to specified buffer.static void
writeMandatory
(io.netty.buffer.ByteBuf buf, Short value, String name) Write aShort
property to specified buffer.static void
writeMandatory
(io.netty.buffer.ByteBuf buf, Uint16 value, String name) Write aUint16
property to specified buffer.static void
writeMandatory
(io.netty.buffer.ByteBuf buf, Uint32 value, String name) Write aUint32
property to specified buffer.static void
writeMandatory
(io.netty.buffer.ByteBuf buf, Uint64 value, String name) Write aUint64
property to specified buffer.static void
writeMandatory
(io.netty.buffer.ByteBuf buf, Uint8 value, String name) Write aUint8
property to specified buffer.static void
writeOptional
(io.netty.buffer.ByteBuf buf, @Nullable Byte value) Write aByte
value to specified buffer if it is not null.static void
writeOptional
(io.netty.buffer.ByteBuf buf, @Nullable Integer value) Write aInteger
value to specified buffer if it is not null.static void
writeOptional
(io.netty.buffer.ByteBuf buf, @Nullable Long value) Write aLong
value to specified buffer if it is not null.static void
writeOptional
(io.netty.buffer.ByteBuf buf, @Nullable Short value) Write aByte
value to specified buffer if it is not null.static void
writeOptional
(io.netty.buffer.ByteBuf buf, @Nullable Uint16 value) Write aUint16
value to specified buffer if it is not null.static void
writeOptional
(io.netty.buffer.ByteBuf buf, @Nullable Uint32 value) Write aUint32
value to specified buffer if it is not null.static void
writeOptional
(io.netty.buffer.ByteBuf buf, @Nullable Uint64 value) Write aUint64
value to specified buffer if it is not null.static void
writeOptional
(io.netty.buffer.ByteBuf buf, @Nullable Uint8 value) Write aUint8
value to specified buffer if it is not null.static void
writeOrZero
(io.netty.buffer.ByteBuf buf, @Nullable Byte value) Write aByte
value to specified buffer if it is not null, otherwise write one zero byte.static void
writeOrZero
(io.netty.buffer.ByteBuf buf, @Nullable Integer value) Write aInteger
value to specified buffer if it is not null, otherwise write four zero bytes.static void
writeOrZero
(io.netty.buffer.ByteBuf buf, @Nullable Long value) Write aByte
value to specified buffer if it is not null, otherwise write eight zero bytes.static void
writeOrZero
(io.netty.buffer.ByteBuf buf, @Nullable Short value) Write aShort
value to specified buffer if it is not null, otherwise write two zero bytes.static void
writeOrZero
(io.netty.buffer.ByteBuf buf, @Nullable Uint16 value) Write aUint16
value to specified buffer if it is not null, otherwise write two zero bytes.static void
writeOrZero
(io.netty.buffer.ByteBuf buf, @Nullable Uint32 value) Write aUint32
value to specified buffer if it is not null, otherwise write four zero bytes.static void
writeOrZero
(io.netty.buffer.ByteBuf buf, @Nullable Uint64 value) Write aUint64
value to specified buffer if it is not null, otherwise write eight zero bytes.static void
writeOrZero
(io.netty.buffer.ByteBuf buf, @Nullable Uint8 value) Write aUint8
value to specified buffer if it is not null, otherwise write one zero byte.static void
writeUint16
(io.netty.buffer.ByteBuf buf, Uint16 value) Write aUint16
to specified buffer.static void
writeUint32
(io.netty.buffer.ByteBuf buf, Uint32 value) Write aUint32
to specified buffer.static void
writeUint64
(io.netty.buffer.ByteBuf buf, Uint64 value) Write aUint64
to specified buffer.static void
writeUint8
(io.netty.buffer.ByteBuf buf, Uint8 value) Write aUint8
to specified buffer.
-
Method Details
-
readUint8
Read anUint8
from specified buffer.- Parameters:
buf
- buffer- Returns:
- A
Uint8
- Throws:
NullPointerException
- ifbuf
is nullIndexOutOfBoundsException
- ifbuf
does not have enough data
-
readUint16
Read aUint16
from specified buffer.- Parameters:
buf
- buffer- Returns:
- A
Uint16
- Throws:
NullPointerException
- ifbuf
is nullIndexOutOfBoundsException
- ifbuf
does not have enough data
-
readUint32
Read aUint32
from specified buffer.- Parameters:
buf
- buffer- Returns:
- A
Uint32
- Throws:
NullPointerException
- ifbuf
is nullIndexOutOfBoundsException
- ifbuf
does not have enough data
-
readUint64
Read aUint64
from specified buffer.- Parameters:
buf
- buffer- Returns:
- A
Uint64
- Throws:
NullPointerException
- ifbuf
is nullIndexOutOfBoundsException
- ifbuf
does not have enough data
-
writeUint8
Write aUint8
to specified buffer.- Parameters:
buf
- buffervalue
- AUint8
- Throws:
NullPointerException
- if any argument is null
-
writeUint16
Write aUint16
to specified buffer.- Parameters:
buf
- buffervalue
- AUint16
- Throws:
NullPointerException
- if any argument is null
-
writeUint32
Write aUint32
to specified buffer.- Parameters:
buf
- buffervalue
- AUint32
- Throws:
NullPointerException
- if any argument is null
-
writeUint64
Write aUint64
to specified buffer.- Parameters:
buf
- buffervalue
- AUint64
- Throws:
NullPointerException
- if any argument is null
-
write
Write aUint8
to 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
Write aUint16
to 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
Write aUint32
to 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
Write aUint64
to 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
Write aByte
property to specified buffer. If thevalue
is known to be non-null, preferByteBuf.writeByte(int)
instead of this method.- Parameters:
buf
- buffervalue
- AByte
name
- Property name for error reporting purposes- Throws:
NullPointerException
- ifbuf
is nullIllegalArgumentException
- ifvalue
is null
-
writeMandatory
Write aShort
property to specified buffer. If thevalue
is known to be non-null, preferByteBuf.writeShort(int)
instead of this method.- Parameters:
buf
- buffervalue
- AShort
name
- Property name for error reporting purposes- Throws:
NullPointerException
- ifbuf
is nullIllegalArgumentException
- ifvalue
is null
-
writeMandatory
Write aInteger
property to specified buffer. If thevalue
is known to be non-null, preferByteBuf.writeInt(int)
instead of this method.- Parameters:
buf
- buffervalue
- AInteger
name
- Property name for error reporting purposes- Throws:
NullPointerException
- ifbuf
is nullIllegalArgumentException
- ifvalue
is null
-
writeMandatory
Write aLong
property to specified buffer. If thevalue
is known to be non-null, preferByteBuf.writeLong(long)
instead of this method.- Parameters:
buf
- buffervalue
- ALong
name
- Property name for error reporting purposes- Throws:
NullPointerException
- ifbuf
is nullIllegalArgumentException
- ifvalue
is null
-
writeMandatory
Write aUint8
property to specified buffer. If thevalue
is known to be non-null, prefer to usewrite(ByteBuf, Uint8)
instead of this method.- Parameters:
buf
- buffervalue
- AUint8
name
- Property name for error reporting purposes- Throws:
NullPointerException
- ifbuf
is nullIllegalArgumentException
- ifvalue
is null
-
writeMandatory
Write aUint16
property to specified buffer. If thevalue
is known to be non-null, prefer to usewrite(ByteBuf, Uint16)
instead of this method.- Parameters:
buf
- buffervalue
- AUint16
name
- Property name for error reporting purposes- Throws:
NullPointerException
- ifbuf
is nullIllegalArgumentException
- ifvalue
is null
-
writeMandatory
Write aUint32
property to specified buffer. If thevalue
is known to be non-null, prefer to usewrite(ByteBuf, Uint32)
instead of this method.- Parameters:
buf
- buffervalue
- AUint32
name
- Property name for error reporting purposes- Throws:
NullPointerException
- ifbuf
is nullIllegalArgumentException
- ifvalue
is null
-
writeMandatory
Write aUint64
property to specified buffer. If thevalue
is known to be non-null, prefer to usewrite(ByteBuf, Uint64)
instead of this method.- Parameters:
buf
- buffervalue
- AUint64
name
- Property name for error reporting purposes- Throws:
NullPointerException
- ifbuf
is nullIllegalArgumentException
- ifvalue
is null
-
writeOptional
Write aByte
value to specified buffer if it is not null.- Parameters:
buf
- buffervalue
- AByte
- Throws:
NullPointerException
- ifbuf
is null
-
writeOptional
Write aByte
value to specified buffer if it is not null.- Parameters:
buf
- buffervalue
- AShort
- Throws:
NullPointerException
- ifbuf
is null
-
writeOptional
Write aInteger
value to specified buffer if it is not null.- Parameters:
buf
- buffervalue
- AInteger
- Throws:
NullPointerException
- ifbuf
is null
-
writeOptional
Write aLong
value to specified buffer if it is not null.- Parameters:
buf
- buffervalue
- ALong
- Throws:
NullPointerException
- ifbuf
is null
-
writeOptional
Write aUint8
value to specified buffer if it is not null.- Parameters:
buf
- buffervalue
- AUint8
- Throws:
NullPointerException
- ifbuf
is null
-
writeOptional
Write aUint16
value to specified buffer if it is not null.- Parameters:
buf
- buffervalue
- AUint16
- Throws:
NullPointerException
- ifbuf
is null
-
writeOptional
Write aUint32
value to specified buffer if it is not null.- Parameters:
buf
- buffervalue
- AUint32
- Throws:
NullPointerException
- ifbuf
is null
-
writeOptional
Write aUint64
value to specified buffer if it is not null.- Parameters:
buf
- buffervalue
- AUint64
- Throws:
NullPointerException
- ifbuf
is null
-
writeOrZero
Write aByte
value to specified buffer if it is not null, otherwise write one zero byte.- Parameters:
buf
- buffervalue
- AByte
- Throws:
NullPointerException
- ifbuf
is null
-
writeOrZero
Write aShort
value to specified buffer if it is not null, otherwise write two zero bytes.- Parameters:
buf
- buffervalue
- AShort
- Throws:
NullPointerException
- ifbuf
is null
-
writeOrZero
Write aInteger
value to specified buffer if it is not null, otherwise write four zero bytes.- Parameters:
buf
- buffervalue
- AInteger
- Throws:
NullPointerException
- ifbuf
is null
-
writeOrZero
Write aByte
value to specified buffer if it is not null, otherwise write eight zero bytes.- Parameters:
buf
- buffervalue
- AByte
- Throws:
NullPointerException
- ifbuf
is null
-
writeOrZero
Write aUint8
value to specified buffer if it is not null, otherwise write one zero byte.- Parameters:
buf
- buffervalue
- AUint8
- Throws:
NullPointerException
- ifbuf
is null
-
writeOrZero
Write aUint16
value to specified buffer if it is not null, otherwise write two zero bytes.- Parameters:
buf
- buffervalue
- AUint16
- Throws:
NullPointerException
- ifbuf
is null
-
writeOrZero
Write aUint32
value to specified buffer if it is not null, otherwise write four zero bytes.- Parameters:
buf
- buffervalue
- AUint32
- Throws:
NullPointerException
- ifbuf
is null
-
writeOrZero
Write aUint64
value to specified buffer if it is not null, otherwise write eight zero bytes.- Parameters:
buf
- buffervalue
- AUint64
- Throws:
NullPointerException
- ifbuf
is null
-