public class MessageCodec extends Object
| Modifier and Type | Field and Description |
|---|---|
static byte[] |
EMPTY_BYTE_ARRAY |
static int |
HEADER_SIZE |
static int |
MAX_BYTE |
| Constructor and Description |
|---|
MessageCodec() |
| Modifier and Type | Method and Description |
|---|---|
static Data |
createData(byte[] me,
int offset,
int length,
int ttl,
boolean protectedEntry,
PeerAddress originator) |
static Data |
decodeData(DataInput buffer,
PeerAddress originator) |
static Message |
decodeHeader(org.jboss.netty.buffer.ChannelBuffer buffer,
InetSocketAddress recipient,
InetSocketAddress sender)
Decode a message header from a Netty buffer
|
static boolean |
decodePayload(Message.Content content,
org.jboss.netty.buffer.ChannelBuffer buffer,
Message message)
Decodes the payload from a Netty buffer in a big switch
|
static PublicKey |
decodePublicKey(DataInput buffer,
byte[] receivedRawPublicKey) |
static boolean |
decodeSignature(Signature signature,
Message message,
org.jboss.netty.buffer.ChannelBuffer buffer) |
static int |
encodeData(ProtocolChunkedInput input,
Message message,
Data data) |
static org.jboss.netty.buffer.ChannelBuffer |
encodeHeader(org.jboss.netty.buffer.ChannelBuffer buffer,
Message message)
The format looks as follows:
32bit p2p version - 32bit id - 4bit message type - 4bit message name -
160bit sender id - 16bit tcp port - 16bit udp port - 160bit recipient id
- 16bit (4x4)content type - 8bit network address
information.
|
static void |
encodePayload(Message message,
ProtocolChunkedInput input)
Encode payload
|
public static final byte[] EMPTY_BYTE_ARRAY
public static final int MAX_BYTE
public static final int HEADER_SIZE
public static org.jboss.netty.buffer.ChannelBuffer encodeHeader(org.jboss.netty.buffer.ChannelBuffer buffer,
Message message)
buffer - The Netty buffer to fillmessage - The message with the header that will be serializedpublic static void encodePayload(Message message, ProtocolChunkedInput input) throws InvalidKeyException, SignatureException, NoSuchAlgorithmException
buffer - The Netty buffer to fillmessage - The message which contains the payloadNoSuchAlgorithmExceptionSignatureExceptionInvalidKeyExceptionpublic static int encodeData(ProtocolChunkedInput input, Message message, Data data)
public static Message decodeHeader(org.jboss.netty.buffer.ChannelBuffer buffer, InetSocketAddress recipient, InetSocketAddress sender) throws DecoderException
buffer - The buffer to decode fromsender - The sender of the packet, which has been set in the socket
classDecoderExceptionpublic static boolean decodePayload(Message.Content content, org.jboss.netty.buffer.ChannelBuffer buffer, Message message) throws InvalidKeyException, SignatureException, NoSuchAlgorithmException, InvalidKeySpecException, IOException, DecoderException
content - The content typebuffer - The buffer to read frommessage - The message to store the resultsIndexOutOfBoundsException - If a buffer is read beyond its limitsNoSuchAlgorithmExceptionSignatureExceptionInvalidKeyExceptionInvalidKeySpecExceptionInvalidKeySpecExceptionIOExceptionDecoderExceptionASN1ExceptionUnsupportedEncodingException - If UTF-8 is not therepublic static Data decodeData(DataInput buffer, PeerAddress originator) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException
public static Data createData(byte[] me, int offset, int length, int ttl, boolean protectedEntry, PeerAddress originator)
public static PublicKey decodePublicKey(DataInput buffer, byte[] receivedRawPublicKey) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException
public static boolean decodeSignature(Signature signature, Message message, org.jboss.netty.buffer.ChannelBuffer buffer) throws NoSuchAlgorithmException, SignatureException, InvalidKeyException, IOException
Copyright © 2011. All Rights Reserved.