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


Java IoBuffer.getShort方法代码示例

本文整理汇总了Java中org.apache.mina.core.buffer.IoBuffer.getShort方法的典型用法代码示例。如果您正苦于以下问题:Java IoBuffer.getShort方法的具体用法?Java IoBuffer.getShort怎么用?Java IoBuffer.getShort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.core.buffer.IoBuffer的用法示例。


在下文中一共展示了IoBuffer.getShort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

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

示例2: processHello

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private boolean processHello ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
    final int len = messageLength ( data );
    if ( len < 0 )
    {
        return false;
    }

    final byte version = data.get ();
    if ( version != 0x01 )
    {
        throw new ProtocolCodecException ( String.format ( "Protocol version %s is unsupported", version ) );
    }

    final short nodeId = data.getShort ();
    final EnumSet<Hello.Features> features = data.getEnumSetShort ( Hello.Features.class );

    out.write ( new Hello ( nodeId, features ) );

    return true;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:ProtocolDecoderImpl.java

示例3: decode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
	//必须保证每一个数据包的字节缓存都和session绑定在一起,不然就读取不了上一次剩余的数据了
	CodecContext context = SessionManager.INSTANCE.getSessionAttr(session, SessionProperties.CODEC_CONTEXT, CodecContext.class);
	if (context == null) {
		context = new CodecContext();
		session.setAttribute(SessionProperties.CODEC_CONTEXT, context);
	}

	IoBuffer ioBuffer = context.getBuffer();
	ioBuffer.put(in);

	//在循环里迭代,以处理数据粘包
	for (; ;) {
		ioBuffer.flip();
		//消息元信息常量4表示消息body前面的两个short字段,一个表示moduel,一个表示cmd,
		final int METE_SIZE = 4;
		if (ioBuffer.remaining() < METE_SIZE) {
			ioBuffer.compact();
			return;
		}
		//----------------消息协议格式-------------------------
		// packetLength | moduleId | cmd   |  body
		//       int       short     short    byte[]
		int length = ioBuffer.getInt();
		//int packLen = length + 4;
		//大于消息body长度,说明至少有一条完整的message消息
		if (ioBuffer.remaining() >= length) {
			short moduleId =  ioBuffer.getShort();
			short cmd = ioBuffer.getShort();
			byte[] body = new byte[length-METE_SIZE];
			ioBuffer.get(body);
			Message msg = readMessage(moduleId, cmd, body);

			if (moduleId > 0) {
				out.write(msg);
			} else { //属于组合包
				CombineMessage combineMessage = (CombineMessage)msg;
				List<Packet> packets = combineMessage.getPackets();
				for (Packet packet :packets) {
					//依次拆包反序列化为具体的Message
					out.write(Packet.asMessage(packet));
				}
			}
			if (ioBuffer.remaining() == 0) {
				ioBuffer.clear();
				break;
			}
			ioBuffer.compact();
		} else{
			//数据包不完整,继续等待数据到达
			ioBuffer.rewind();
			ioBuffer.compact();
			break;
		}
	}
}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:57,代码来源:MessageDecoder.java

示例4: get

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


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