java.lang.Object
net.i2p.data.i2cp.I2CPMessageImpl
net.i2p.data.i2cp.MessagePayloadMessage
- All Implemented Interfaces:
I2CPMessage
Defines the payload message a router sends to the client.
Field Summary
Modifier and TypeFieldDescriptionprivate longThe message the payload belongs to.private PayloadThe message contents.private intThe session the payload is for.static final intI2CP message type code for a payload message.Constructor Summary
ConstructorsConstructorDescriptionFor reading.MessagePayloadMessage(long sessID, long msgID, Payload payload) For writing.Method Summary
Public MethodsModifier and TypeMethodDescriptionprotected voiddoReadMessage(InputStream in, int size) Read in the payload part of the message (after the initial 4 byte size and 1 byte type).protected byte[]Write the message body to the output stream.longGet the message ID, unique within the session.Get the payload carried by this message.longGet the session this message was sent on.intgetType()Return the unique identifier for this type of message, as specified in the network specification document under #ClientAccessLayerMessages.Return the SessionId for this message.toString()voidwriteMessage(OutputStream out) Write out the full message to the stream, including the 4 byte size and 1 byte type header.Methods inherited from class I2CPMessageImpl
readBytes, readMessage, readMessage, writeBytesModifier and TypeMethodDescriptionvoidreadBytes(InputStream in) Read the message from the stream, wrapping I2CPMessageException inDataFormatException.voidValidate the type and size of the message, and then read the message into the data structures.voidreadMessage(InputStream in, int length, int type) Read the body into the data structures.voidwriteBytes(OutputStream out) Write the message to the stream, wrapping I2CPMessageException in DataFormatException.
Field Details
MESSAGE_TYPE
public static final int MESSAGE_TYPEI2CP message type code for a payload message.- See Also:
_sessionId
private int _sessionIdThe session the payload is for._messageId
private long _messageIdThe message the payload belongs to._payload
The message contents.
Constructor Details
MessagePayloadMessage
public MessagePayloadMessage()For reading. Deprecated for writing, use 3-arg constructor.MessagePayloadMessage
For writing.- Parameters:
sessID- the session the message belongs to, stored truncated to 32 bitsmsgID- the message ID used to correlate the payload with its replypayload- the payload to deliver to the session
Method Details
getSessionId
public long getSessionId()Get the session this message was sent on.- Returns:
- the session ID
sessionId
Return the SessionId for this message.- Specified by:
sessionIdin interfaceI2CPMessage- Overrides:
sessionIdin classI2CPMessageImpl- Returns:
- null always. Extending classes with a SessionId must override.
getMessageId
public long getMessageId()Get the message ID, unique within the session.- Returns:
- the message ID
getPayload
Get the payload carried by this message.- Returns:
- the payload to deliver to the session, or null if not yet set
doReadMessage
Read in the payload part of the message (after the initial 4 byte size and 1 byte type).- Specified by:
doReadMessagein classI2CPMessageImpl- Parameters:
in- positioned just past the 4 byte size and 1 byte type headersize- how many payload bytes remain to be read- Throws:
I2CPMessageException- if the message format is invalidIOException- if there's an error reading from the stream
doWriteMessage
Write the message body to the output stream.- Specified by:
doWriteMessagein classI2CPMessageImpl- Returns:
- byte array
- Throws:
UnsupportedOperationException- always, as this message is read-only once constructedI2CPMessageException- if the message cannot be writtenIOException- if there's an error writing to the stream
writeMessage
Write out the full message to the stream, including the 4 byte size and 1 byte type header.- Specified by:
writeMessagein interfaceI2CPMessage- Overrides:
writeMessagein classI2CPMessageImpl- Parameters:
out- receives the length, type and payload, in that order- Throws:
IOException- if there's an error writing to the streamI2CPMessageException- if the current object doesn't have sufficient data to write a properly formatted message.
getType
public int getType()Return the unique identifier for this type of message, as specified in the network specification document under #ClientAccessLayerMessages.- Returns:
- unique identifier for this type of message
toString