本文整理汇总了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 );
}