本文整理匯總了Java中org.apache.mina.core.buffer.IoBuffer.putShort方法的典型用法代碼示例。如果您正苦於以下問題:Java IoBuffer.putShort方法的具體用法?Java IoBuffer.putShort怎麽用?Java IoBuffer.putShort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.mina.core.buffer.IoBuffer
的用法示例。
在下文中一共展示了IoBuffer.putShort方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: encodeWriteRequestsData
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
/**
* Encode the data section of the write request
*
* @param message
* @param data
*/
private void encodeWriteRequestsData ( final DaveWriteRequest message, final IoBuffer data )
{
for ( final DaveWriteRequest.Request request : message.getRequests () )
{
if ( request.getType () == AddressType.BIT )
{
data.put ( new byte[] { 0x00, 0x03 } );
}
else
{
data.put ( new byte[] { 0x00, 0x04 } );
}
final IoBuffer requestData = request.getData ();
data.putShort ( (short) ( request.getCount () * startFactor ( request ) ) );
data.put ( requestData );
}
}
示例2: encodeHeader
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void encodeHeader ( final DaveMessage message, final IoBuffer data, final byte type )
{
// == PDU header
data.put ( PACKET_START_MAGIC );
data.put ( type );
data.put ( (byte)0 );
data.put ( (byte)0 );
data.putShort ( (short)0 ); // req nr
data.putShort ( (short)0 ); // parameter len
data.putShort ( (short)0 ); // data len
if ( type == 2 || type == 3 )
{
data.put ( (byte)0 );
data.put ( (byte)0 );
}
}
示例3: createMessage
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
protected IoBuffer createMessage ( final IoSession session, final byte command, final boolean longMessage )
{
final IoBuffer data = IoBuffer.allocate ( 3 );
data.setAutoExpand ( true );
if ( Sessions.isLittleEndian ( session ) )
{
data.order ( ByteOrder.LITTLE_ENDIAN );
}
data.put ( (byte)0x12 );
data.put ( (byte)0x02 );
data.put ( command );
if ( longMessage )
{
data.putShort ( (short)0 );
}
return data;
}
示例4: writeMessage
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private IoBuffer writeMessage(Message message) {
//----------------消息協議格式-------------------------
// packetLength | moduleId | cmd | body
// int short short byte[]
IoBuffer buffer = IoBuffer.allocate(CodecContext.WRITE_CAPACITY);
buffer.setAutoExpand(true);
//消息內容長度,先占個坑
buffer.putInt(0);
short moduleId = message.getModule();
short cmd = message.getCmd();
//寫入module類型
buffer.putShort(moduleId);
//寫入cmd類型
buffer.putShort(cmd);
//寫入具體消息的內容
byte[] body = wrapMessageBody(moduleId, cmd, message);
buffer.put(body);
//回到buff字節數組頭部
buffer.flip();
//消息元信息,兩個short,共4個字節
final int METE_SIZE = 4;
//重新寫入包體長度
buffer.putInt(buffer.limit() - METE_SIZE);
buffer.rewind();
return buffer;
}
示例5: encodeAddress
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
/**
* Encode the request address in the parameters area
*
* @param data
* @param request
*/
private void encodeAddress ( final IoBuffer data, final Request request )
{
data.put ( (byte)0x12 );
data.put ( (byte)0x0a ); // could be the length of the parameter
data.put ( (byte)0x10 );
data.put ( request.getType ().getType () );
data.putShort ( request.getCount () ); // length in bytes
data.putShort ( request.getBlock () ); // DB number
data.put ( request.getArea () );
data.putMediumInt ( request.getStart () * startFactor ( request ) ); // start address in bits
}
示例6: finishEncode
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void finishEncode ( final IoBuffer data, final short parameterLen, final short dataLen )
{
// set parameter len
data.putShort ( 6, parameterLen );
// set data len
data.putShort ( 8, dataLen );
}
示例7: encode
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void encode ( final IoSession session, final Object message, final ProtocolEncoderOutput out ) throws Exception
{
logger.debug ( "Encoding: {}", message );
final Pdu request = (Pdu)message;
final IoBuffer buffer = IoBuffer.allocate ( request.getData ().remaining () + 3 );
buffer.setAutoExpand ( true );
final IoBuffer pdu = request.getData ();
// put slave id
buffer.put ( request.getUnitIdentifier () );
// put data
buffer.put ( pdu );
// make and put crc
final int crc = Checksum.crc16 ( buffer.array (), 0, pdu.limit () + 1 ); // including slave address
buffer.order ( ByteOrder.LITTLE_ENDIAN );
buffer.putShort ( (short)crc );
buffer.flip ();
logger.trace ( "Encoded to: {}", buffer );
out.write ( buffer );
}
示例8: encodeWriteRequest
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void encodeWriteRequest ( final IoBuffer data, final WriteRequestMessage message )
{
data.putShort ( message.getIndex () );
final Object value = message.getData ();
if ( value == null )
{
data.put ( (byte)0x00 );
}
else if ( value instanceof Boolean )
{
data.put ( (byte)0x01 );
data.put ( (byte) ( (Boolean)value ? 0xFF : 0x00 ) );
}
else if ( value instanceof Float || value instanceof Double )
{
data.put ( (byte)0x04 );
data.putFloat ( ( (Number)value ).floatValue () );
}
else if ( value instanceof Long )
{
data.put ( (byte)0x03 );
data.putLong ( ( (Number)value ).longValue () );
}
else if ( value instanceof Number )
{
data.put ( (byte)0x02 );
data.putInt ( ( (Number)value ).intValue () );
}
else if ( value instanceof String )
{
data.put ( (byte)0x02 );
data.putInt ( Integer.parseInt ( (String)value ) );
}
else
{
throw new RuntimeException ( String.format ( "Unable to write request of type %s", value.getClass () ) );
}
}
示例9: encodeHeader
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void encodeHeader ( final IoBuffer data, final CommonMessage message )
{
data.putShort ( (short)1202 );
data.put ( (byte)0x01 );
data.putInt ( message.getSequence () );
data.put ( message.getCommandCode ().getCommandCode () );
}
示例10: filterWrite
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void filterWrite ( final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest ) throws Exception
{
// we only handle IoBuffers
if ( writeRequest.getMessage () instanceof IoBuffer )
{
final IoBuffer inData = (IoBuffer)writeRequest.getMessage ();
final IoBuffer outData = IoBuffer.allocate ( inData.remaining () + 4 );
// put the version, the reserved
outData.put ( (byte)this.version );
outData.put ( (byte)0 );
// and the data length
outData.putShort ( (short) ( inData.remaining () + 4 ) );
// append the data itself
outData.put ( inData );
outData.flip ();
logger.debug ( "TPKT out: {}", outData );
// pass on data buffer
nextFilter.filterWrite ( session, new WriteRequestWrapper ( writeRequest ) {
@Override
public Object getMessage ()
{
return outData;
}
} );
}
else
{
nextFilter.filterWrite ( session, writeRequest );
}
}
示例11: putValue
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void putValue ( final IoBuffer slice, final Variant value )
{
slice.putShort ( makeValue ( value ) );
}
示例12: put
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void put ( final IoBuffer data, final Short value )
{
data.putShort ( value );
}