當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。