FileDocCategorySizeDatePackage
GenericMessageEncoder.javaAPI DocAzureus 3.0.3.42368Fri Feb 16 16:30:44 GMT 2007org.gudy.azureus2.pluginsimpl.local.messaging

GenericMessageEncoder

public class GenericMessageEncoder extends Object implements com.aelitis.azureus.core.peermanager.messaging.MessageStreamEncoder

Fields Summary
Constructors Summary
Methods Summary
public com.aelitis.azureus.core.networkmanager.RawMessage[]encodeMessage(com.aelitis.azureus.core.peermanager.messaging.Message _message)

		GenericMessage	message = (GenericMessage)_message;
		
		DirectByteBuffer	payload = message.getPayload();
		
		if ( message.isAlreadyEncoded()){
			
			return( 
				new RawMessage[]{
					new RawMessageImpl( 
						message, 
						new DirectByteBuffer[]{ payload }, 
						RawMessage.PRIORITY_NORMAL, 
						true,	// send immediately 
						new Message[0] )});
			
		}else{
			
			DirectByteBuffer 	header = DirectByteBufferPool.getBuffer( DirectByteBuffer.AL_EXTERNAL, 4 );
			
			header.putInt( DirectByteBuffer.SS_MSG, payload.remaining( DirectByteBuffer.SS_MSG ));
			
			header.flip( DirectByteBuffer.SS_MSG );
			
			return( 
				new RawMessage[]{
					new RawMessageImpl( 
						message, 
						new DirectByteBuffer[]{ header, payload }, 
						RawMessage.PRIORITY_NORMAL, 
						true,	// send immediately 
						new Message[0] )});
		}