本文整理匯總了Java中org.apache.mina.core.buffer.IoBuffer.putUnsignedShort方法的典型用法代碼示例。如果您正苦於以下問題:Java IoBuffer.putUnsignedShort方法的具體用法?Java IoBuffer.putUnsignedShort怎麽用?Java IoBuffer.putUnsignedShort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.mina.core.buffer.IoBuffer
的用法示例。
在下文中一共展示了IoBuffer.putUnsignedShort方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convertData
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
/**
* Encode the data from Java byte order to requested modbus byte order
*
* @param data
* the data to encode
* @param dataOrder
* the target modbus byte order
* @return the converted data, or the input data if no conversion was
* necessary
*/
public static IoBuffer convertData ( final IoBuffer data, final ByteOrder dataOrder )
{
if ( dataOrder == ByteOrder.BIG_ENDIAN )
{
return data;
}
final IoBuffer result = IoBuffer.allocate ( data.capacity () );
result.order ( dataOrder );
for ( int i = 0; i < data.remaining () / 2; i++ )
{
// convert to LITTLE_ENDIAN
result.putUnsignedShort ( data.getUnsignedShort ( i * 2 ) );
}
// the byte order we use is BIG_ENDIAN
result.order ( ByteOrder.BIG_ENDIAN );
return result;
}
示例2: encodeBrowseUpdate
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void encodeBrowseUpdate ( final IoSession session, final Object message, final IoBuffer data ) throws ProtocolCodecException
{
// length
data.putUnsignedShort ( ( (BrowseAdded)message ).getEntries ().size () );
final CharsetEncoder encoder = Sessions.getCharsetEncoder ( session );
// data
for ( final BrowseAdded.Entry entry : ( (BrowseAdded)message ).getEntries () )
{
data.putUnsignedShort ( entry.getRegister () );
data.put ( entry.getDataType ().getDataType () );
data.putEnumSet ( entry.getFlags () );
try
{
data.putPrefixedString ( entry.getName (), encoder );
data.putPrefixedString ( entry.getDescription (), encoder );
data.putPrefixedString ( entry.getUnit (), encoder );
}
catch ( final CharacterCodingException e )
{
throw new ProtocolCodecException ( e );
}
}
}
示例3: encodeProperties
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void encodeProperties ( final IoBuffer data, final Map<String, String> properties ) throws ProtocolCodecException
{
final CharsetEncoder encoder = this.defaultCharset.newEncoder ();
data.putUnsignedShort ( properties.size () );
for ( final Map.Entry<String, String> entry : properties.entrySet () )
{
try
{
data.putPrefixedString ( entry.getKey (), encoder );
data.putPrefixedString ( entry.getValue (), encoder );
}
catch ( final CharacterCodingException e )
{
throw new ProtocolCodecException ( e );
}
}
}
示例4: makeReadReply
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
protected Object makeReadReply ( final BaseMessage baseMessage, final int[] data, final ByteOrder order )
{
final IoBuffer reply = IoBuffer.allocate ( data.length * 2 );
reply.order ( order );
for ( int i = 0; i < data.length; i++ )
{
reply.putUnsignedShort ( data[i] );
}
reply.flip ();
return new ReadResponse ( baseMessage.getTransactionId (), baseMessage.getUnitIdentifier (), baseMessage.getFunctionCode (), reply );
}
示例5: 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 () + 7 );
buffer.setAutoExpand ( true );
final IoBuffer pdu = request.getData ();
// put transaction identifier
buffer.putUnsignedShort ( request.getTransactionId () );
// put modbus protocol identifier (always 0)
buffer.putUnsignedShort ( 0 );
// put length, including slave id
buffer.putUnsignedShort ( request.getData ().remaining () + 1 );
// put slave id
buffer.put ( request.getUnitIdentifier () );
// put data
buffer.put ( pdu );
buffer.flip ();
logger.trace ( "Encoded to: {}", buffer );
out.write ( buffer );
}
示例6: encodeEntry
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void encodeEntry ( final IoSession session, final IoBuffer data, final Entry entry ) throws ProtocolCodecException
{
data.putUnsignedShort ( entry.getRegister () );
data.put ( entry.getMissedUpdates () );
data.putLong ( entry.getTimestamp () );
data.putEnumSetShort ( entry.getStates () );
// put payload
encodeVariant ( session, data, entry.getValue () );
}
示例7: putValue
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void putValue ( final IoBuffer slice, final Variant value )
{
slice.putUnsignedShort ( makeValue ( value ) );
}
示例8: put
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void put ( final IoBuffer data, final Integer value )
{
data.putUnsignedShort ( value );
}