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 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(org.jboss.netty.buffer.ChannelBuffer buffer, byte[] receivedRawPublicKey)
           
static boolean decodeSignature(Signature signature, Message message, org.jboss.netty.buffer.ChannelBuffer buffer)
           
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
 
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 - 16bit (4x4)content type - 8bit network address information. It total, the header is of size 56 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,
                                 ProtocolChunkedInput input)
                          throws InvalidKeyException,
                                 SignatureException,
                                 NoSuchAlgorithmException,
                                 ClassNotFoundException,
                                 IOException
Encode payload

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

decodeHeader

public static Message decodeHeader(org.jboss.netty.buffer.ChannelBuffer buffer,
                                   InetSocketAddress recipient,
                                   InetSocketAddress 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 boolean decodePayload(Message.Content content,
                                    org.jboss.netty.buffer.ChannelBuffer buffer,
                                    Message message)
                             throws InvalidKeyException,
                                    SignatureException,
                                    NoSuchAlgorithmException,
                                    InvalidKeySpecException,
                                    IOException,
                                    DecoderException
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
DecoderException
ASN1Exception
UnsupportedEncodingException - If UTF-8 is not there

decodePublicKey

public static PublicKey decodePublicKey(org.jboss.netty.buffer.ChannelBuffer buffer,
                                        byte[] receivedRawPublicKey)
                                 throws InvalidKeyException,
                                        NoSuchAlgorithmException,
                                        InvalidKeySpecException
Throws:
InvalidKeyException
NoSuchAlgorithmException
InvalidKeySpecException

decodeSignature

public static boolean decodeSignature(Signature signature,
                                      Message message,
                                      org.jboss.netty.buffer.ChannelBuffer buffer)
                               throws NoSuchAlgorithmException,
                                      SignatureException,
                                      InvalidKeyException,
                                      IOException
Throws:
NoSuchAlgorithmException
SignatureException
InvalidKeyException
IOException


Copyright © 2013. All Rights Reserved.