Interface ZigBeeDataOutput
-
public interface ZigBeeDataOutputTheZigBeeDataOutputinterface is designed for converting Java data types into a series of bytes. The purpose of this interface is the same as the DataOutput interface provided by Java, with the difference that in this interface, the generated bytes ordering is little endian, whereas in the DataOutput is big endian.- Author:
- $Id: 881f0d5fc3869f01558c34796ba78b3faee5b31f $
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidwriteByte(byte value)Appends a byte to the data output.voidwriteBytes(byte[] bytes, int length)Appends on the Data Output Stream a byte array.voidwriteDouble(double value)Appends on the Data Output Stream adoublevalue.voidwriteFloat(float value, int size)Appends on the Data Output Stream a float value.voidwriteInt(int value, int size)Appends an int value to the data output.voidwriteLong(long value, int size)Appends a long to the data output.
-
-
-
Method Detail
-
writeByte
void writeByte(byte value)
Appends a byte to the data output.To avoid losing information, the passed value must be in the range [-128, 127] for signed numbers and [0, 255] for unsigned numbers.
- Parameters:
value- The value to append.
-
writeInt
void writeInt(int value, int size) throws java.io.IOExceptionAppends an int value to the data output.To avoid losing information, according to the
sizeargument, the passedlongvalue if it represents a signed number must fit in the range [ -2^(size* 8 - 1), -2^(size* 8 - 1) - 1].For unsigned numbers it should fit in the range [ 0, -2^(
size* 8) - 1].For instance if
sizeis 2 the correct range for signed numbers is [0xffff8000, 0x7fff] (that is, [-32768, +32767]), whereas for unsigned numbers is [0L, 0xffff].Although this method allows write even 1 byte of the passed
intvalue, it is suggested to use thewriteByte(byte)because this latter could be implemented in a more efficient way.- Parameters:
value- The integer value to appendsize- The size in bytes that have to be actually appended. The size must be in the range [1,4].- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- If the passedsizeis not within the allowed range.
-
writeLong
void writeLong(long value, int size) throws java.io.IOExceptionAppends a long to the data output.To avoid losing information, according to the
sizeargument, the passedlongvalue if it represents a signed number must fit in the range [ -2^(size* 8 - 1), -2^(size* 8 - 1) - 1].For unsigned numbers it should fit in the range [ 0, -2^(
size* 8) - 1].For instance if
sizeis 3 the correct range for signed numbers is [0xffffffffff800000L, 0x7fffffL] (that is, [-21474836448, +2147483647]), whereas for unsigned numbers is [0L, 0xffffffL].Although this method allows write even 1 byte of the passed
longvalue, it is suggested to use thewriteByte(byte)because this latter could be implemented in a more efficient way.- Parameters:
value- Thelongvalue to appendsize- The size in bytes that have to be actually appended. The size must be in the range [1,8].- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- If the passedsizeis not within the allowed range.
-
writeFloat
void writeFloat(float value, int size) throws java.io.IOExceptionAppends on the Data Output Stream a float value.- Parameters:
value- Thefloatvalue to append.size- The size in bytes that have to be actually appended. The size must be 2 for semi precision floats or 4 for standard precision floats (see the ZigBee Cluster Library specifications).- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- If the passedsizeis not within the allowed range.
-
writeDouble
void writeDouble(double value) throws java.io.IOExceptionAppends on the Data Output Stream adoublevalue.- Parameters:
value- Thedoublevalue to append.- Throws:
java.io.IOException- If an I/O error occurs.
-
writeBytes
void writeBytes(byte[] bytes, int length) throws java.io.IOExceptionAppends on the Data Output Stream a byte array. The byte array is written on the data output starting from the byte at index 0.- Parameters:
bytes- A buffer containing the bytes to append to the data output stream.length- The length in bytes that have to be actually appended.- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- If the passed buffer is null or shorter thanlengthbytes.
-
-