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 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 command - 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, ClassNotFoundException, IOException
buffer
- The Netty buffer to fillmessage
- The message which contains the payloadNoSuchAlgorithmException
SignatureException
InvalidKeyException
IOException
ClassNotFoundException
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
classDecoderException
public 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 limitsNoSuchAlgorithmException
SignatureException
InvalidKeyException
InvalidKeySpecException
InvalidKeySpecException
IOException
DecoderException
ASN1Exception
UnsupportedEncodingException
- If UTF-8 is not therepublic static PublicKey decodePublicKey(org.jboss.netty.buffer.ChannelBuffer 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 © 2013. All Rights Reserved.