当前位置: 首页>>代码示例>>Java>>正文


Java IoBuffer.putShort方法代码示例

本文整理汇总了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 );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:28,代码来源:DaveFilter.java

示例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 );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:DaveFilter.java

示例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;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:20,代码来源:ProtocolEncoderImpl.java

示例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;
}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:31,代码来源:MessageEncoder.java

示例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
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:20,代码来源:DaveFilter.java

示例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 );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:8,代码来源:DaveFilter.java

示例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 );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:28,代码来源:ModbusRtuEncoder.java

示例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 () ) );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:39,代码来源:ArduinoCodec.java

示例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 () );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:8,代码来源:ArduinoCodec.java

示例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 );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:38,代码来源:TPKTFilter.java

示例11: putValue

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void putValue ( final IoBuffer slice, final Variant value )
{
    slice.putShort ( makeValue ( value ) );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:6,代码来源:ShortIntegerType.java

示例12: put

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void put ( final IoBuffer data, final Short value )
{
    data.putShort ( value );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:6,代码来源:Int16Accessor.java


注:本文中的org.apache.mina.core.buffer.IoBuffer.putShort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。