Class WritableObjects
java.lang.Object
org.opendaylight.yangtools.concepts.WritableObjects
Utility methods for working with
WritableObject
s.-
Method Summary
Modifier and TypeMethodDescriptionstatic int
longHeaderFlags
(byte header) Extract user-defined flags from a compressed long header.static long
readFirstLong
(DataInput in, byte header) Read first long value from an input.static long
Read a long value from aDataInput
which was previously written viawriteLong(DataOutput, long)
.static long
readLongBody
(DataInput in, byte header) Read a long value from aDataInput
as hinted by the result ofreadLongHeader(DataInput)
.static byte
Read the header of a compressed long value.static long
readSecondLong
(DataInput in, byte header) Read second long value from an input.static void
writeLong
(DataOutput out, long value) Shorthand forwriteLong(DataOutput, long, int)
with zero flags.static void
writeLong
(DataOutput out, long value, int flags) Write a long value into aDataOutput
, compressing potential zero bytes.static void
writeLongs
(DataOutput out, long value0, long value1) Write two consecutive long values.
-
Method Details
-
writeLong
Shorthand forwriteLong(DataOutput, long, int)
with zero flags.- Parameters:
out
- Data outputvalue
- long value to write- Throws:
IOException
- if an I/O error occursNullPointerException
- ifout
isnull
-
writeLong
Write a long value into aDataOutput
, compressing potential zero bytes. This method is useful for serializing counters and similar, which have a wide range, but typically do not use it. The value provided is treated as unsigned.This methods writes the number of trailing non-zero in the value. It then writes the minimum required bytes to reconstruct the value by left-padding zeroes. Inverse operation is performed by
readLong(DataInput)
or a combination ofreadLongHeader(DataInput)
andreadLongBody(DataInput, byte)
.Additionally the caller can use the top four bits (i.e.
0xF0
) for caller-specific flags. These will be ignored byreadLong(DataInput)
, but can be extracted viareadLongHeader(DataInput)
.- Parameters:
out
- Data outputvalue
- long value to writeflags
- flags to store- Throws:
IOException
- if an I/O error occursNullPointerException
- ifout
isnull
-
readLong
Read a long value from aDataInput
which was previously written viawriteLong(DataOutput, long)
.- Parameters:
in
- Data input- Returns:
- long value extracted from the data input
- Throws:
IOException
- if an I/O error occursNullPointerException
- ifin
isnull
-
readLongHeader
Read the header of a compressed long value. The header may contain user-defined flags, which can be extracted vialongHeaderFlags(byte)
.- Parameters:
in
- Data input- Returns:
- Header of next value
- Throws:
IOException
- if an I/O error occursNullPointerException
- ifin
isnull
-
longHeaderFlags
public static int longHeaderFlags(byte header) Extract user-defined flags from a compressed long header. This will return {code 0} if the long value originates fromwriteLong(DataOutput, long)
.- Parameters:
header
- Value header, as returned byreadLongHeader(DataInput)
- Returns:
- User-defined flags
-
readLongBody
Read a long value from aDataInput
as hinted by the result ofreadLongHeader(DataInput)
.- Parameters:
in
- Data inputheader
- Value header, as returned byreadLongHeader(DataInput)
- Returns:
- long value
- Throws:
IOException
- if an I/O error occursNullPointerException
- ifin
isnull
-
writeLongs
Write two consecutive long values. These values can be read back usingreadLongHeader(DataInput)
,readFirstLong(DataInput, byte)
andreadSecondLong(DataInput, byte)
.This is a more efficient way of serializing two longs than
writeLong(DataOutput, long)
. This is achieved by using the flags field to hold the length of the second long -- hence saving one byte.- Parameters:
out
- Data outputvalue0
- first long value to writevalue1
- second long value to write- Throws:
IOException
- if an I/O error occursNullPointerException
- ifout
isnull
-
readFirstLong
Read first long value from an input.- Parameters:
in
- Data inputheader
- Value header, as returned byreadLongHeader(DataInput)
- Returns:
- First long specified in
writeLongs(DataOutput, long, long)
- Throws:
IOException
- if an I/O error occursNullPointerException
- if input is null
-
readSecondLong
Read second long value from an input.- Parameters:
in
- Data inputheader
- Value header, as returned byreadLongHeader(DataInput)
- Returns:
- Second long specified in
writeLongs(DataOutput, long, long)
- Throws:
IOException
- if an I/O error occursNullPointerException
- ifin
isnull
-