Class ValueBuffer
java.lang.Object
org.openhab.core.io.transport.modbus.ValueBuffer
ByteBuffer-like interface for working with different types of data stored in byte arrays
- Author:
- Sami Salonen - Initial contribution
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
array()
Returns underlying bytesget
(byte[] dst) Starting from current position, read dst.length number of bytes and copy the data to dstfloat
Extract single-precision 32-bit IEEE 754 floating point at current position, and advance position.float
Extract single-precision 32-bit IEEE 754 floating point at current position, and advance position.short
Extract signed 16-bit integer at current position, and advance position.int
Extract signed 32-bit integer at current position, and advance position.int
Extract signed 32-bit integer at current position, and advance position.long
Extract signed 64-bit integer at current position, and advance position.long
Extract signed 64-bit integer at current position, and advance position.byte
getSInt8()
Extract signed 8-bit integer at current position, and advance position.int
Extract unsigned 16-bit integer at current position, and advance position.long
Extract unsigned 32-bit integer at current position, and advance position.long
Extract unsigned 32-bit integer at current position, and advance position.Extract unsigned 64-bit integer at current position, and advance position.Extract unsigned 64-bit integer at current position, and advance position.short
getUInt8()
Extract unsigned 8-bit integer at current position, and advance position.boolean
Tells whether there are any bytes left between current position and the endmark()
Sets this buffer's mark at its position.int
position()
Returns this buffer's position.position
(int byteIndex) Sets this buffer's position.int
Returns the number of bytes between the current position and the end.reset()
Resets this buffer's position to the previously-marked position.static ValueBuffer
wrap
(byte[] array) Wrap given bytes and create a new instance of ValueBuffer The instance will have position of 0.static ValueBuffer
wrap
(ModbusRegisterArray array) Wrap modbus registers and create a new instance of ValueBuffer The instance will have position of 0.
-
Method Details
-
wrap
Wrap modbus registers and create a new instance of ValueBuffer The instance will have position of 0.- Parameters:
array
- set of registers- Returns:
- new instance of ValueBuffer referencing bytes represented by modbus register array
-
wrap
Wrap given bytes and create a new instance of ValueBuffer The instance will have position of 0.- Parameters:
array
- set of bytes to wrap- Returns:
- new instance of ValueBuffer referencing bytes
-
position
public int position()Returns this buffer's position.- Returns:
- The position of this buffer
-
position
Sets this buffer's position. If the mark is defined and larger than the new position then it is discarded.- Returns:
- this buffer
-
mark
Sets this buffer's mark at its position.- Returns:
- this buffer
-
reset
Resets this buffer's position to the previously-marked position. Invoking this method neither changes nor discards the mark's value.- Returns:
- this buffer
- Throws:
InvalidMarkException
- If the mark has not been set
-
remaining
public int remaining()Returns the number of bytes between the current position and the end.- Returns:
- The number of bytes remaining in this buffer
-
array
public byte[] array()Returns underlying bytes- Returns:
- reference to underlying bytes
-
hasRemaining
public boolean hasRemaining()Tells whether there are any bytes left between current position and the end- Returns:
- true if, and only if, there is at least one byte remaining in this buffer
-
get
Starting from current position, read dst.length number of bytes and copy the data to dst- Parameters:
dst
- copied bytes- Returns:
- this buffer
- Throws:
BufferOverflowException
- If there is insufficient space in this buffer for the remaining bytes in the source buffer
-
getSInt8
public byte getSInt8()Extract signed 8-bit integer at current position, and advance position.- Returns:
- signed 8-bit integer (byte)
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getUInt8
public short getUInt8()Extract unsigned 8-bit integer at current position, and advance position.- Returns:
- unsigned 8-bit integer
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getSInt16
public short getSInt16()Extract signed 16-bit integer at current position, and advance position.- Returns:
- signed 16-bit integer (short)
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getUInt16
public int getUInt16()Extract unsigned 16-bit integer at current position, and advance position.- Returns:
- unsigned 16-bit integer
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getSInt32
public int getSInt32()Extract signed 32-bit integer at current position, and advance position.- Returns:
- signed 32-bit integer
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getUInt32
public long getUInt32()Extract unsigned 32-bit integer at current position, and advance position.- Returns:
- unsigned 32-bit integer
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getSInt32Swap
public int getSInt32Swap()Extract signed 32-bit integer at current position, and advance position. This is identical with getSInt32, but with registers swapped.- Returns:
- signed 32-bit integer
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getUInt32Swap
public long getUInt32Swap()Extract unsigned 32-bit integer at current position, and advance position. This is identical with getUInt32, but with registers swapped.- Returns:
- unsigned 32-bit integer
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getSInt64
public long getSInt64()Extract signed 64-bit integer at current position, and advance position.- Returns:
- signed 64-bit integer
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getUInt64
Extract unsigned 64-bit integer at current position, and advance position.- Returns:
- unsigned 64-bit integer
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getSInt64Swap
public long getSInt64Swap()Extract signed 64-bit integer at current position, and advance position. This is identical with getSInt64, but with registers swapped.- Returns:
- signed 64-bit integer
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getUInt64Swap
Extract unsigned 64-bit integer at current position, and advance position. This is identical with getUInt64, but with registers swapped.- Returns:
- unsigned 64-bit integer
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getFloat32
public float getFloat32()Extract single-precision 32-bit IEEE 754 floating point at current position, and advance position. Note that this method can return floating point NaN and floating point infinity.- Returns:
- single-precision 32-bit IEEE 754 floating point
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-
getFloat32Swap
public float getFloat32Swap()Extract single-precision 32-bit IEEE 754 floating point at current position, and advance position. This is identical with getFloat32, but with registers swapped. Note that this method can return floating point NaN and floating point infinity.- Returns:
- single-precision 32-bit IEEE 754 floating point
- Throws:
IllegalArgumentException
- when there are not enough bytes in this ValueBuffer- See Also:
-