本文整理汇总了Java中org.apache.mina.core.buffer.IoBuffer.getInt方法的典型用法代码示例。如果您正苦于以下问题:Java IoBuffer.getInt方法的具体用法?Java IoBuffer.getInt怎么用?Java IoBuffer.getInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.core.buffer.IoBuffer
的用法示例。
在下文中一共展示了IoBuffer.getInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processWriteResult
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private boolean processWriteResult ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
final int len = messageLength ( data );
if ( len < 0 )
{
return false;
}
try
{
final int operationId = data.getInt ();
final int errorCode = data.getUnsignedShort ();
final String errorMessage = decodeString ( session, data );
out.write ( new WriteResult ( operationId, errorCode, errorMessage ) );
}
catch ( final CharacterCodingException e )
{
throw new ProtocolCodecException ( e );
}
return true;
}
示例2: decode
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void decode ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput output ) throws Exception
{
final short magic = data.getShort ();
final byte version = data.get ();
final int sequence = data.getInt ();
final byte commandCode = data.get ();
if ( magic != 1202 )
{
throw new ProtocolCodecException ( String.format ( "Magic code should be 1202 but is %s", magic ) );
}
if ( version != 1 )
{
throw new ProtocolCodecException ( String.format ( "Version should be %s but is %s", 1, version ) );
}
decodeMessage ( sequence, commandCode, data, output );
}
示例3: decodeEnumList
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public <E extends Enum<E>> List<E> decodeEnumList ( final IoBuffer buffer, final Class<E> enumClazz ) throws Exception
{
final byte type = checkType ( buffer, TYPE_ENUM_LIST, true );
if ( type == TYPE_NULL )
{
return null;
}
final int len = buffer.getInt ();
final List<E> result = new ArrayList<E> ( len );
for ( int i = 0; i < len; i++ )
{
result.add ( inlineDecodeEnum ( buffer, enumClazz ) );
}
return result;
}
示例4: decodeBooleanCollection
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private <T extends Collection<Boolean>> T decodeBooleanCollection ( final IoBuffer buffer, final CollectionAllocator<Boolean, T> allactor ) throws Exception
{
final byte type = checkType ( buffer, TYPE_BOOLEAN_LIST, true );
if ( type == TYPE_NULL )
{
return null;
}
else
{
final int items = buffer.getInt ();
final T result = allactor.allocate ( items );
fillBooleanCollection ( buffer, items, result );
return result;
}
}
示例5: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.ae.data.message.StartBrowse decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.ae.data.message.StartBrowse ();
}
示例6: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.hd.data.message.StartBrowse decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.hd.data.message.StartBrowse ();
}
示例7: beginReadStructureList
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public Integer beginReadStructureList ( final IoBuffer buffer, final boolean allowNull ) throws Exception
{
final byte type = checkType ( buffer, TYPE_STRUCTURE_LIST, allowNull );
if ( type == TYPE_NULL )
{
return null;
}
return buffer.getInt ();
}
示例8: decodable
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public MessageDecoderResult decodable(IoSession session, IoBuffer in)
{
Context context = (Context) session.getAttribute(CONTEXT);
if(context!=null){
if(context.limit_data){
in.buf().position(0);
}
}
//表示数据不够,需要读到新的数据后,再次调用decode()方法。
if (in.remaining() < 2){
return MessageDecoderResult.NEED_DATA;
}
else{
context = new Context();
//获取一个字符表示新的数据开始 用于判断异常数据
in.skip(1);//这个数据是十六进制的 01 也就是1
//获取第一个字符用于判断是否可以被当前解码器解码
context.dataType = in.getInt();
if(context.dataType == BeanUtil.UPLOAD_STR){
//读取标题长度
context.strLength = in.getInt();
//声明数组长度
context.byteStr = new byte[context.strLength];
//System.out.println("我收到2了");
session.setAttribute(CONTEXT, context);
//表示可以解码
return MessageDecoderResult.OK;
}else{
//System.out.println("服务端收到意外数据");
return MessageDecoderResult.NOT_OK;
}
}
}
示例9: inlineDecodeProperties
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
protected Map<String, String> inlineDecodeProperties ( final IoBuffer buffer ) throws Exception
{
final int len = buffer.getInt ();
final Map<String, String> result = new HashMap<String, String> ( len );
for ( int i = 0; i < len; i++ )
{
final String key = this.stringInterner.intern ( buffer.getPrefixedString ( STRING_PREFIX_LEN, this.decoder ) );
final String value = this.stringInterner.intern ( buffer.getPrefixedString ( STRING_PREFIX_LEN, this.decoder ) );
result.put ( key, value );
}
return result;
}
示例10: decode
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public MessageDecoderResult decode(IoSession session, IoBuffer buf, ProtocolDecoderOutput out) throws Exception {
CjyTcpMessage message = new CjyTcpMessage();
logger.info("收到采集仪消息" + buf.getHexDump());
buf.mark();
//帧起始符 0x68
buf.get();
// 获取设备编码
int address_i = buf.getInt();
message.setAddress(CommUtils.highAndLowAddressSwap(address_i));
//帧起始符 0x16
if ( buf.get() != 0x68){
return null;
}
//控制码
byte control = buf.get();
message.setD7(control >> 7);
message.setD6(control >> 6);
//控制码 , 协议簇
message.setCmd(control&0x0f);
//数据体长度
int length = buf.get();
message.setLength(length);
//数据体
byte[] data = MessageUtil.getBytes(buf, length);
message.setData(data);
//CRC
byte crc = (buf.get());
//结束标志
int finished = buf.get();
if ( finished != 0x16 ){
return MessageDecoderResult.NOT_OK;
}
buf.reset();
//获取校验位前字节
byte[] cpData = MessageUtil.getBytes(buf, 8 + length);
int t = 0;
for( int i =0; i< cpData.length; i ++){
t += cpData[i];
}
int crc_cal = (t%256) ;
logger.info("获取的CRC值" + (crc & 0xFF) + ",计算的crc值:" + crc_cal + ",address:" + message.getAddress());
//如果校验码校验不通过,则为无效消息
if ( (crc & 0xFF) != (crc_cal & 0xFF)){
return MessageDecoderResult.NOT_OK;
}
buf.get();
buf.get();
out.write(message);
return MessageDecoderResult.OK;
}
示例11: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.ae.data.message.UpdateQueryData decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
long queryId = 0L;
java.util.List<org.eclipse.scada.ae.data.EventInformation> events = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
queryId = _context.decodePrimitiveLong ( _data );
}
break;
case 2:
{
events = org.eclipse.scada.ae.protocol.ngp.codec.Structures.decodeListEventInformation ( _context, _data, true );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.ae.data.message.UpdateQueryData ( queryId, events );
}
示例12: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.da.data.message.WriteValueResult decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
org.eclipse.scada.core.data.Response response = null;
org.eclipse.scada.core.data.ErrorInformation errorInformation = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
response = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeResponse ( _context, _data, false );
}
break;
case 2:
{
errorInformation = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeErrorInformation ( _context, _data, true );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.da.data.message.WriteValueResult ( response, errorInformation );
}
示例13: doDecode
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
protected boolean doDecode ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput output ) throws Exception
{
logger.trace ( "decode data - session: {}, data: {}", session, data );
if ( data.remaining () < HEADER_SIZE )
{
return false;
}
final int position = data.position ();
final byte version = data.get ( position ); // peek at version
if ( version != 0x01 )
{
throw new IllegalStateException ( String.format ( "Version 0x%02x is not supported.", version ) );
}
final int frameTypeOrdinal = data.get ( position + 1 ); // peek at frame type
final FrameType frameType = FrameType.values ()[frameTypeOrdinal]; // may case an exception, that is ok then
final int dataLength = data.getInt ( position + 2 ); // we need to look at "here" + 2
logger.trace ( "Data length: {}, remainingData: {}", dataLength, data.remaining () - 6 );
if ( data.remaining () < HEADER_SIZE + dataLength )
{
return false;
}
// consume fields
data.get (); // version - #0
data.get (); // frame type - #1
data.getInt (); // dataLength - #2
// data - #6
final IoBuffer frameData = data.getSlice ( dataLength ); // this also consumes the buffer 'data'
final Frame frame = new Frame ( frameType, frameData );
logger.trace ( "Decoded frame: {} ... {} bytes remaining", frame, data.remaining () );
output.write ( frame );
return true;
}
示例14: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.da.data.message.BrowseFolder decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
org.eclipse.scada.core.data.Request request = null;
java.util.List<String> location = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
request = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeRequest ( _context, _data, false );
}
break;
case 2:
{
location = _context.decodeStringList ( _data );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.da.data.message.BrowseFolder ( request, location );
}
示例15: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.hd.data.message.CreateQueryFailure decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
org.eclipse.scada.core.data.Response response = null;
org.eclipse.scada.core.data.ErrorInformation errorInformation = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
response = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeResponse ( _context, _data, false );
}
break;
case 2:
{
errorInformation = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeErrorInformation ( _context, _data, false );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.hd.data.message.CreateQueryFailure ( response, errorInformation );
}