Interface PartialReadMessage
- All Superinterfaces:
AutoCloseable
,io.netty.util.ReferenceCounted
,RemoteMessage
- All Known Implementing Classes:
ArmedProtocolMessage
,UnarmedProtocolMessage
@UnstableApi
public interface PartialReadMessage
extends RemoteMessage, io.netty.util.ReferenceCounted, AutoCloseable
Describes a message whose content has been read partially. This is the case for encrypted
messages, chunks or messages that do not need to be read completely.
- See Also:
-
Field Summary
Fields inherited from interface org.drasyl.handler.remote.protocol.RemoteMessage
MAGIC_NUMBER, MAGIC_NUMBER_LEN
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
CallsReferenceCounted.release()
.io.netty.buffer.ByteBuf
getBytes()
Returns the remainder of unread bytes of this message.static PartialReadMessage
of
(io.netty.buffer.ByteBuf bytes) Creates aPartialReadMessage
frombytes
.static PartialReadMessage
of
(PublicHeader publicHeader, io.netty.buffer.ByteBuf bytes) Methods inherited from interface io.netty.util.ReferenceCounted
refCnt, release, release, retain, retain, touch, touch
Methods inherited from interface org.drasyl.handler.remote.protocol.RemoteMessage
encodeMessage, getArmed, getHopCount, getLength, getNetworkId, getNonce, getProofOfWork, getRecipient, getSender, incrementHopCount
-
Method Details
-
getBytes
io.netty.buffer.ByteBuf getBytes()Returns the remainder of unread bytes of this message.- Returns:
- the remainder of unread bytes of this message
-
close
void close()CallsReferenceCounted.release()
.- Specified by:
close
in interfaceAutoCloseable
-
of
Creates aPartialReadMessage
frompublicHeader
andbytes
.- In case
publicHeader.getArmed()
istrue
,ArmedProtocolMessage
object is returned. - In all other cases,
UnarmedProtocolMessage
object is returned.
ReferenceCounted.release()
ownership ofbytes
is transferred to thisPartialReadMessage
.Modifying the content of
bytes
or the returned message's buffer affects each other's content while they maintain separate indexes and marks.- Parameters:
publicHeader
- message's public headerbytes
- message's remainder as bytes (may be armed).ReferenceCounted.release()
ownership is transferred to thisPartialReadMessage
.- Returns:
- an
PartialReadMessage
object - Throws:
NullPointerException
- ifpublicHeader.getNonce()
,publicHeader.getSender()
,publicHeader.getProofOfWork()
, orpublicHeader.getRecipient()
isnull
IllegalArgumentException
- ifpublicHeader.getSender()
orpublicHeader.getRecipient()
has wrong key size, orpublicHeader.getAgreementId()
is neithernull
nor a valid SHA256 hash
- In case
-
of
Creates aPartialReadMessage
frombytes
. First, this method checks ifbytes
starts withRemoteMessage.MAGIC_NUMBER
, then reads the message's public header:- In case
publicHeader.getArmed()
istrue
,ArmedProtocolMessage
object is returned. - In all other cases,
UnarmedProtocolMessage
object is returned.
ReferenceCounted.release()
ownership ofbytes
is transferred to thisPartialReadMessage
.Modifying the content of
bytes
or the returned message's buffer affects each other's content while they maintain separate indexes and marks.- Parameters:
bytes
- message's bytes (may be partially armed).ReferenceCounted.release()
ownership is transferred to thisPartialReadMessage
.- Returns:
- an
PartialReadMessage
object - Throws:
NullPointerException
- ifpublicHeader.getNonce()
,publicHeader.getSender()
,publicHeader.getProofOfWork()
, orpublicHeader.getRecipient()
isnull
IllegalArgumentException
- ifpublicHeader.getSender()
orpublicHeader.getRecipient()
has wrong key size, orpublicHeader.getAgreementId()
is neithernull
nor a valid SHA256 hashInvalidMessageFormatException
- if magic number or public header is missing
- In case
-