public interface BinaryMessage
extends org.macroing.cit.messaging.Message
Message
that can be sent to a MessageChannel
.
It is specifically designed to be transmitted over a network.
Any non-public implementations of this interface may throw an UnsupportedOperationException
for any methods not being used. Such implementations should, however, preferably document this behavior.
Modifier and Type | Interface and Description |
---|---|
static interface |
BinaryMessage.Builder
Builder is used for building BinaryMessage instances. |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the amount of
byte s that can be read without blocking. |
byte[] |
getBytes()
Returns an array of
byte s. |
int |
getIdentifier()
Returns the identifier assigned to this
BinaryMessage . |
boolean |
isHeadless()
Returns
true if, and only if, this BinaryMessage can be considered head-less, false otherwise. |
int |
length()
Returns the length of this
BinaryMessage at this time. |
BinaryMessage |
newIdentifier(int identifier)
Returns a new
BinaryMessage with the same content, but with a new identifier. |
int |
readBits(int numberOfBits)
Reads
numberOfBits bits. |
int |
readByte()
Reads a
byte as an int . |
int |
readInt()
Reads an
int . |
long |
readLong()
Reads a
long . |
int |
readShort()
Reads a
short as an int . |
java.lang.String |
readString()
Reads a
String with length available() . |
java.lang.String |
readString(int length)
Reads a
String with length length . |
BinaryMessage newIdentifier(int identifier)
BinaryMessage
with the same content, but with a new identifier.identifier
- the new identifierBinaryMessage
with the same content, but with a new identifierboolean isHeadless()
true
if, and only if, this BinaryMessage
can be considered head-less, false
otherwise.
A BinaryMessage
that is head-less, may very well return an identifier if requested to, but that identifier should not be part of the data being sent to some end-point. That is, there should be no meaning attached to its identifier.
true
if, and only if, this BinaryMessage
can be considered head-less, false
otherwisebyte[] getBytes()
byte
s.
This method should never return null
.
byte
sint available()
byte
s that can be read without blocking.byte
s that can be read without blockingint getIdentifier()
BinaryMessage
.BinaryMessage
int length()
BinaryMessage
at this time.
The length includes all previously read byte
s and any available.
BinaryMessage
at this timeint readBits(int numberOfBits)
numberOfBits
bits.
Returns an int
denoting the read value.
This method may block if no data is currently available.
numberOfBits
- the number of bits to readint
denoting the read valueint readByte()
byte
as an int
.
Returns an int
denoting the read value.
This method may block if no data is currently available.
The read offset is increased by 1
.
int
denoting the read valueint readInt()
int
.
This method may block if no data is currently available.
The read offset is increased by 4
.
int
denoting the read valueint readShort()
short
as an int
.
Returns an int
denoting the read value.
This method may block if no data is currently available.
The read offset is increased by 2
.
int
denoting the read valuelong readLong()
long
.
This method may block if no data is currently available.
The read offset is increased by 8
.
long
denoting the read valuejava.lang.String readString()
String
with length available()
.
The read offset is increased by available()
.
String
denoting the read valuejava.lang.String readString(int length)
String
with length length
.
This method may block if length
is greater than available()
.
The read offset is increased by length
.
If length
is less than 0
, an IllegalArgumentException
may be thrown. But no guarantees can be made.
length
- the length of the String
to be readString
denoting the read valuejava.lang.IllegalArgumentException
- thrown if, and only if, length
is less than 0