Package net.i2p.data.i2cp
Class I2CPMessageImpl
java.lang.Object
net.i2p.data.i2cp.I2CPMessageImpl
- All Implemented Interfaces:
I2CPMessage
- Direct Known Subclasses:
BandwidthLimitsMessage
,BlindingInfoMessage
,CreateLeaseSetMessage
,CreateSessionMessage
,DestLookupMessage
,DestReplyMessage
,DestroySessionMessage
,DisconnectMessage
,GetBandwidthLimitsMessage
,GetDateMessage
,HostLookupMessage
,HostReplyMessage
,MessagePayloadMessage
,MessageStatusMessage
,PoisonI2CPMessage
,ReceiveMessageBeginMessage
,ReceiveMessageEndMessage
,ReconfigureSessionMessage
,ReportAbuseMessage
,RequestLeaseSetMessage
,RequestVariableLeaseSetMessage
,SendMessageMessage
,SessionStatusMessage
,SetDateMessage
public abstract class I2CPMessageImpl extends Object implements I2CPMessage
Defines the base message implementation.
As of 0.9.48, does NOT extend DataStructureImpl.
- Author:
- jrandom
-
Constructor Summary
Constructors Constructor Description I2CPMessageImpl()
-
Method Summary
Modifier and Type Method Description protected abstract void
doReadMessage(InputStream buf, int size)
Read in the payload part of the message (after the initial 4 byte size and 1 byte type)protected abstract byte[]
doWriteMessage()
Write out the payload part of the message (not including the 4 byte size and 1 byte type)void
readBytes(InputStream in)
void
readMessage(InputStream in)
Validate the type and size of the message, and then read the message into the data structures.void
readMessage(InputStream in, int length, int type)
Read the body into the data structuresSessionId
sessionId()
Return the SessionId for this type of message.void
writeBytes(OutputStream out)
void
writeMessage(OutputStream out)
Write out the full message to the stream, including the 4 byte size and 1 byte type header.
-
Constructor Details
-
I2CPMessageImpl
public I2CPMessageImpl()
-
-
Method Details
-
readMessage
Validate the type and size of the message, and then read the message into the data structures.- Specified by:
readMessage
in interfaceI2CPMessage
- Parameters:
in
- stream to read from- Throws:
IOException
I2CPMessageException
- if the stream doesn't contain a valid message that this class can read.
-
readMessage
public void readMessage(InputStream in, int length, int type) throws I2CPMessageException, IOExceptionRead the body into the data structures- Specified by:
readMessage
in interfaceI2CPMessage
- Parameters:
length
- number of bytes in the message payloadin
- stream to read fromtype
- type of message (should equal getType())- Throws:
IOException
I2CPMessageException
- if the stream doesn't contain a valid message that this class can read.
-
doReadMessage
protected abstract void doReadMessage(InputStream buf, int size) throws I2CPMessageException, IOExceptionRead in the payload part of the message (after the initial 4 byte size and 1 byte type)- Parameters:
buf
- InputStreamsize
- payload size- Throws:
I2CPMessageException
IOException
-
doWriteMessage
Write out the payload part of the message (not including the 4 byte size and 1 byte type)- Returns:
- byte array
- Throws:
I2CPMessageException
IOException
-
writeMessage
Write out the full message to the stream, including the 4 byte size and 1 byte type header.- Specified by:
writeMessage
in interfaceI2CPMessage
- Parameters:
out
- OutputStream- Throws:
IOException
I2CPMessageException
- if the current object doesn't have sufficient data to write a properly formatted message.
-
readBytes
- Throws:
DataFormatException
IOException
-
writeBytes
- Throws:
DataFormatException
IOException
-
sessionId
Return the SessionId for this type of message. Most but not all message types include a SessionId. The ones that do already define getSessionId(), but some return a SessionId and some return a long, so we define a new method here.- Specified by:
sessionId
in interfaceI2CPMessage
- Returns:
- null always. Extending classes with a SessionId must override.
- Since:
- 0.9.21
-