net.tomp2p.message
Class MessageCodec

java.lang.Object
  extended by net.tomp2p.message.MessageCodec

public class MessageCodec
extends Object


Field Summary
static byte[] EMPTY_BYTE_ARRAY
           
static int HEADER_SIZE
           
static int MAX_BYTE
           
 
Constructor Summary
MessageCodec()
           
 
Method Summary
static Data createData(byte[] me, int offset, int length, int ttl, boolean protectedEntry, PeerAddress originator)
           
static Data decodeData(DataInput buffer, Message message)
           
static Message decodeHeader(org.jboss.netty.buffer.ChannelBuffer buffer, InetAddress sender)
          Decode a message header from a Netty buffer
static void 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 int encodeData(Collection<DataOutput> result, DataOutputFactory factory, 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 - 32bit message length - 16bit (4x4)content type - 8bit network address information.
static void encodePayload(Message message, List<org.jboss.netty.buffer.ChannelBuffer> payloadBuffers)
          Encode payload
static void encodeSecurity(Message message, List<org.jboss.netty.buffer.ChannelBuffer> buffers)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_BYTE_ARRAY

public static final byte[] EMPTY_BYTE_ARRAY

MAX_BYTE

public static final int MAX_BYTE
See Also:
Constant Field Values

HEADER_SIZE

public static final int HEADER_SIZE
See Also:
Constant Field Values
Constructor Detail

MessageCodec

public MessageCodec()
Method Detail

encodeHeader

public 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 - 32bit message length - 16bit (4x4)content type - 8bit network address information. It total, the header is of size 60 bytes.

Parameters:
buffer - The Netty buffer to fill
message - The message with the header that will be serialized
Returns:
The buffer passed as an argument

encodePayload

public static void encodePayload(Message message,
                                 List<org.jboss.netty.buffer.ChannelBuffer> payloadBuffers)
                          throws InvalidKeyException,
                                 SignatureException,
                                 NoSuchAlgorithmException
Encode payload

Parameters:
buffer - The Netty buffer to fill
message - The message which contains the payload
Throws:
NoSuchAlgorithmException
SignatureException
InvalidKeyException

encodeSecurity

public static void encodeSecurity(Message message,
                                  List<org.jboss.netty.buffer.ChannelBuffer> buffers)
                           throws NoSuchAlgorithmException,
                                  InvalidKeyException,
                                  SignatureException,
                                  IOException
Throws:
NoSuchAlgorithmException
InvalidKeyException
SignatureException
IOException

encodeData

public static int encodeData(Collection<DataOutput> result,
                             DataOutputFactory factory,
                             Message message,
                             Data data)

decodeHeader

public static Message decodeHeader(org.jboss.netty.buffer.ChannelBuffer buffer,
                                   InetAddress sender)
                            throws DecoderException
Decode a message header from a Netty buffer

Parameters:
buffer - The buffer to decode from
sender - The sender of the packet, which has been set in the socket class
Returns:
The partial message, only the header fields are filled
Throws:
DecoderException

decodePayload

public static void decodePayload(Message.Content content,
                                 org.jboss.netty.buffer.ChannelBuffer buffer,
                                 Message message)
                          throws InvalidKeyException,
                                 SignatureException,
                                 NoSuchAlgorithmException,
                                 InvalidKeySpecException,
                                 IOException
Decodes the payload from a Netty buffer in a big switch

Parameters:
content - The content type
buffer - The buffer to read from
message - The message to store the results
Throws:
IndexOutOfBoundsException - If a buffer is read beyond its limits
NoSuchAlgorithmException
SignatureException
InvalidKeyException
InvalidKeySpecException
InvalidKeySpecException
IOException
ASN1Exception
UnsupportedEncodingException - If UTF-8 is not there

decodeData

public static Data decodeData(DataInput buffer,
                              Message message)
                       throws InvalidKeyException,
                              NoSuchAlgorithmException,
                              InvalidKeySpecException,
                              UnknownHostException
Throws:
InvalidKeyException
NoSuchAlgorithmException
InvalidKeySpecException
UnknownHostException

createData

public static Data createData(byte[] me,
                              int offset,
                              int length,
                              int ttl,
                              boolean protectedEntry,
                              PeerAddress originator)

decodePublicKey

public static PublicKey decodePublicKey(DataInput buffer,
                                        byte[] receivedRawPublicKey)
                                 throws InvalidKeyException,
                                        NoSuchAlgorithmException,
                                        InvalidKeySpecException
Throws:
InvalidKeyException
NoSuchAlgorithmException
InvalidKeySpecException


Copyright © 2011. All Rights Reserved.