• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MessageDecoderResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.mina.filter.codec.demux.MessageDecoderResult的典型用法代码示例。如果您正苦于以下问题:Java MessageDecoderResult类的具体用法?Java MessageDecoderResult怎么用?Java MessageDecoderResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MessageDecoderResult类属于org.apache.mina.filter.codec.demux包,在下文中一共展示了MessageDecoderResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: decode

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
public MessageDecoderResult decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out)
        throws ProtocolCodecException {
    int messageCount = 0;
    while (parseMessage(in, out)) {
        messageCount++;
    }
    if (messageCount > 0) {
        // Mina will compact the buffer because we can't detect a header
        if (in.remaining() < HEADER_PATTERN.length) {
            position = 0;
        }
        return MessageDecoderResult.OK;
    } else {
        // Mina will compact the buffer
        position -= in.position();
        return MessageDecoderResult.NEED_DATA;
    }
}
 
开发者ID:fix-protocol-tools,项目名称:STAFF,代码行数:19,代码来源:FixMessageDecoder.java


示例2: decodable

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
@Override
public MessageDecoderResult decodable(IoSession session, IoBuffer buf) {
	int remain = buf.remaining();
	if(remain <= 1){
		return  MessageDecoderResult.NOT_OK;
	}
	buf.mark();
	byte[] data = new byte[remain - 2];
	buf.get(data);
	byte cs = buf.get();
	int t = 0;
	for( int i =0; i< data.length; i ++){
		t += data[i];
	}
	int cs_cal = (t%256) ;
	
	//如果校验码校验不通过,则为无效消息
	if ( (cs & 0xFF) != (cs_cal & 0xFF)){
		buf.reset();
		return MessageDecoderResult.NOT_OK;
	}
	buf.reset();
	return MessageDecoderResult.OK;
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:25,代码来源:MessageTcpDecoder.java


示例3: decode

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
/**
 * 解码并处理断包
 */
@Override
public MessageDecoderResult decode(IoSession session, IoBuffer buffer, ProtocolDecoderOutput output)
		throws Exception {
	int nRemainning = buffer.remaining();
	if (nRemainning < MessageCodec.HEAD_LENGTH) {// min length
		return MessageDecoderResult.NEED_DATA;
	} else {
		buffer.mark();// 标记位置mark=pos
		int nLen = buffer.getShort();// 包长(包括消息头)
		buffer.reset();// 重置位置pos=mark

		// 如果buffer中可读的长度小于包长说明断包返回 NEED_DATA
		if (nRemainning < nLen) {
			// buffer.reset();//重置位置pos=mark
			return MessageDecoderResult.NEED_DATA;
		}
		// buffer.reset();//重置位置pos=mark
	}

	Object proObj = decodeBody(session, buffer);
	output.write(proObj);// 解码后输出
	return MessageDecoderResult.OK;
}
 
开发者ID:East196,项目名称:maker,代码行数:27,代码来源:ProtobufMessageDecoder.java


示例4: decodeCommonHeader

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
protected MessageDecoderResult decodeCommonHeader(AbstractMessage message, IoBuffer in) {
    //Common decoding part
    if (in.remaining() < 2) {
        return NEED_DATA;
    }
    byte h1 = in.get();
    byte messageType = (byte) ((h1 & 0x00F0) >> 4);
    boolean dupFlag = ((byte) ((h1 & 0x0008) >> 3) == 1);
    byte qosLevel = (byte) ((h1 & 0x0006) >> 1);
    boolean retainFlag = ((byte) (h1 & 0x0001) == 1);
    int remainingLength = Utils.decodeRemainingLenght(in);
    if (remainingLength == -1) {
        return NEED_DATA;
    }

    message.setMessageType(messageType);
    message.setDupFlag(dupFlag);
    message.setQos(AbstractMessage.QOSType.values()[qosLevel]);
    message.setRetainFlag(retainFlag);
    message.setRemainingLength(remainingLength);
    return OK;
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:23,代码来源:MqttDecoder.java


示例5: decode

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    //Common decoding part
    UnsubscribeMessage message = new UnsubscribeMessage();
    if (decodeCommonHeader(message, in) == NEED_DATA) {
        return NEED_DATA;
    }
    
    //check qos level
    if (message.getQos() != QOSType.LEAST_ONE) {
        return NOT_OK;
    }
        
    int start = in.position();
    //read  messageIDs
    message.setMessageID(Utils.readWord(in));
    int readed = in.position() - start;
    while (readed < message.getRemainingLength()) {
        message.addTopic(Utils.decodeString(in));
        readed = in.position() - start;
    }
    
    out.write(message);
    return OK;
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:25,代码来源:UnsubscribeDecoder.java


示例6: decode

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
     //Common decoding part
    SubscribeMessage message = new SubscribeMessage();
    if (decodeCommonHeader(message, in) == NEED_DATA) {
        return NEED_DATA;
    }
    
    //check qos level
    if (message.getQos() != QOSType.LEAST_ONE) {
        return NOT_OK;
    }
        
    int start = in.position();
    //read  messageIDs
    message.setMessageID(Utils.readWord(in));
    int readed = in.position() - start;
    while (readed < message.getRemainingLength()) {
        decodeSubscription(in, message);
        readed = in.position() - start;
    }
    
    out.write(message);
    return OK;
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:25,代码来源:SubscribeDecoder.java


示例7: checkDecodable

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
static MessageDecoderResult checkDecodable(byte type, IoBuffer in) {
    if (in.remaining() < 1) {
        return MessageDecoderResult.NEED_DATA;
    }
    byte h1 = in.get();
    byte messageType = (byte) ((h1 & 0x00F0) >> 4);
    
    int remainingLength = Utils.decodeRemainingLenght(in);
    if (remainingLength == -1) {
        return MessageDecoderResult.NEED_DATA;
    }
    
    //check remaining length
    if (in.remaining() < remainingLength) {
        return MessageDecoderResult.NEED_DATA;
    }
    
    return messageType == type ? MessageDecoderResult.OK : MessageDecoderResult.NOT_OK;
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:20,代码来源:Utils.java


示例8: decode

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    //Common decoding part
    SubAckMessage message = new SubAckMessage();
    if (decodeCommonHeader(message, in) == NEED_DATA) {
        return NEED_DATA;
    }
    int remainingLength = message.getRemainingLength();
    
    //MessageID
    message.setMessageID(Utils.readWord(in));
    remainingLength -= 2;
    
    //Qos array
    if (in.remaining() < remainingLength ) {
        return NEED_DATA;
    }
    for (int i = 0; i < remainingLength; i++) {
        byte qos = in.get();
        message.addType(QOSType.values()[qos]);
    }
    
    out.write(message);
    return OK;
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:25,代码来源:SubAckDecoder.java


示例9: testBadFlagUserPwd

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
@Test
public void testBadFlagUserPwd() throws UnsupportedEncodingException, Exception {
    m_buff = IoBuffer.allocate(14);
    m_buff.clear().put((byte)(AbstractMessage.CONNECT << 4)).put((byte)12);
    //Proto name
    encodeString(m_buff, "MQIsdp");
    //version
    m_buff.put((byte)3);
    //conn flags
    m_buff.put((byte)0x4E); //sets user to false and password to true
    //keepAlive
    m_buff.put((byte)0).put((byte) 0x0A);
    m_buff.flip();
    
    //Excercise
    MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder);
    
    assertNull(m_mockProtoDecoder.getMessage());
    assertEquals(MessageDecoder.NOT_OK, res);
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:21,代码来源:ConnectDecoderTest.java


示例10: testMultiTopic

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
@Test
public void testMultiTopic() throws Exception {
    m_buff = IoBuffer.allocate(4).setAutoExpand(true);
    String topic1 = "a/b";
    String topic2 = "c/d/e";
    initMultiTopic(m_buff, 123, topic1, topic2);
    m_buff.flip();
    
    //Excercise
    MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder);

    //Verify
    assertEquals(MessageDecoderResult.OK, res);
    assertEquals(2, m_mockProtoDecoder.getMessage().topics().size());
    assertEquals(topic1, m_mockProtoDecoder.getMessage().topics().get(0));
    assertEquals(topic2, m_mockProtoDecoder.getMessage().topics().get(1));
    assertEquals(AbstractMessage.UNSUBSCRIBE, m_mockProtoDecoder.getMessage().getMessageType());
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:19,代码来源:UnsubscribeDecoderTest.java


示例11: testDecodeSingleTopic_bug

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
@Test
    public void testDecodeSingleTopic_bug() throws Exception {
        //A2 0C 00 01 00 06 2F 74 6F 70 69 63 //12 byte
        byte[] overallMessage = new byte[] {(byte)0xA2, 0x0A, //fixed header
             0x00, 0x01, //MSG ID
             0x00, 0x06, 0x2F, 0x74, 0x6F, 0x70, 0x69, 0x63}; //"/topic" string
        m_buff = IoBuffer.allocate(overallMessage.length).setAutoExpand(true);
        m_buff.put(overallMessage);
        m_buff.flip();
         
        MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder);

        assertNotNull(m_mockProtoDecoder.getMessage());
        UnsubscribeMessage message = (UnsubscribeMessage) m_mockProtoDecoder.getMessage();
//        assertEquals(0x0A, message.getMessageID());
//        assertEquals(1, message.types().size());
//        assertEquals(AbstractMessage.QOSType.LEAST_ONE, message.types().get(0));
        
    }
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:20,代码来源:UnsubscribeDecoderTest.java


示例12: testBadQos

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
@Test
public void testBadQos() throws Exception {
    initHeaderQos(m_buff, 0xAABB, QOSType.LEAST_ONE, QOSType.MOST_ONE, QOSType.MOST_ONE);
    m_buff.flip();

    //Excercise
    MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder);

    //Verify
    assertEquals(MessageDecoderResult.OK, res);
    assertEquals(0xAABB, m_mockProtoDecoder.getMessage().getMessageID().intValue());
    List<QOSType> qoses = m_mockProtoDecoder.getMessage().types();
    assertEquals(3, qoses.size());
    assertEquals(QOSType.LEAST_ONE, qoses.get(0));
    assertEquals(QOSType.MOST_ONE, qoses.get(1));
    assertEquals(QOSType.MOST_ONE, qoses.get(2));
    assertEquals(AbstractMessage.SUBACK, m_mockProtoDecoder.getMessage().getMessageType());
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:19,代码来源:SubAckDecoderTest.java


示例13: testBugBadRemainingCalculation

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
@Test
public void testBugBadRemainingCalculation() throws Exception {
    byte[] overallMessage = new byte[] {(byte)0x90, 0x03, //fixed header
         0x00, 0x0A, //MSG ID
         0x01}; //QoS array
     m_buff = IoBuffer.allocate(overallMessage.length).setAutoExpand(true);
     m_buff.put(overallMessage);
     m_buff.flip();
     
     //Exercise
    MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder);

    assertNotNull(m_mockProtoDecoder.getMessage());
    assertEquals(MessageDecoder.OK, res);
    SubAckMessage message = (SubAckMessage) m_mockProtoDecoder.getMessage();
    assertEquals(0x0A, message.getMessageID().intValue());
    assertEquals(1, message.types().size());
    assertEquals(AbstractMessage.QOSType.LEAST_ONE, message.types().get(0));
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:20,代码来源:SubAckDecoderTest.java


示例14: testMultiTopic

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
@Test
public void testMultiTopic() throws Exception {
    m_buff = IoBuffer.allocate(4).setAutoExpand(true);
    Couple c1 = new Couple((byte)2, "a/b");
    Couple c2 = new Couple((byte)1, "c/d/e");
    initMultiTopic(m_buff, 123, c1, c2);
    m_buff.flip();
    
    //Excercise
    MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder);

    //Verify
    assertEquals(MessageDecoderResult.OK, res);
    assertEquals(2, m_mockProtoDecoder.getMessage().subscriptions().size());
    assertEquals(AbstractMessage.SUBSCRIBE, m_mockProtoDecoder.getMessage().getMessageType());
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:17,代码来源:SubscribeDecoderTest.java


示例15: testHeaderWithMessageID_Payload

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
@Test
public void testHeaderWithMessageID_Payload() throws Exception {
    m_buff = IoBuffer.allocate(14).setAutoExpand(true);
    int messageID = 123;
    byte[] payload = new byte[]{0x0A, 0x0B, 0x0C};
    initHeaderWithMessageID_Payload(m_buff, messageID, payload);
    m_buff.flip();

    //Exercise
    MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder);

    assertNotNull(m_mockProtoDecoder.getMessage());
    assertEquals(MessageDecoder.OK, res);
    assertEquals("Fake Topic", m_mockProtoDecoder.getMessage().getTopicName());
    assertEquals(messageID, (int) m_mockProtoDecoder.getMessage().getMessageID());
    TestUtils.verifyEquals(payload, m_mockProtoDecoder.getMessage().getPayload());
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:18,代码来源:PublishDecoderTest.java


示例16: testBugOnRealCase

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
@Test
public void testBugOnRealCase() throws Exception {
    byte[] overallMessage = new byte[]{0x30, 0x17, //fixed header, 25 byte lenght
        0x00, 0x06, 0x2f, 0x74, 0x6f, 0x70, 0x69, 0x63, //[/topic] string 2 len + 6 content
        0x54, 0x65, 0x73, 0x74, 0x20, 0x6d, 0x79, // [Test my payload] encoding
        0x20, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64};
    m_buff = IoBuffer.allocate(overallMessage.length).setAutoExpand(true);
    m_buff.put(overallMessage);
    m_buff.flip();

    //Exercise
    MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder);

    assertNotNull(m_mockProtoDecoder.getMessage());
    assertEquals(MessageDecoder.OK, res);
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:17,代码来源:PublishDecoderTest.java


示例17: testDecodeBigContent

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
@Test
public void testDecodeBigContent() throws Exception {
    int size = 129;
    IoBuffer payload = TestUtils.generateRandomPayload(size);

    IoBuffer firstPublish = generatePublishQoS0(payload);
    IoBuffer secondPublish = generatePublishQoS0(TestUtils.generateRandomPayload(size));

    IoBuffer doubleMessageBuf = IoBuffer.allocate(size * 2).setAutoExpand(true);
    doubleMessageBuf.put(firstPublish).put(secondPublish).flip();


    //Exercise
    MessageDecoderResult res = m_msgdec.decode(null, doubleMessageBuf, m_mockProtoDecoder);

    assertEquals(MessageDecoder.OK, res);
    PublishMessage pubMsg = m_mockProtoDecoder.getMessage();
    assertNotNull(pubMsg);

    res = m_msgdec.decode(null, doubleMessageBuf, m_mockProtoDecoder);

    assertNotNull(m_mockProtoDecoder.getMessage());
    assertEquals(MessageDecoder.OK, res);

    m_buff.flip();
}
 
开发者ID:milliondreams,项目名称:moquette-mqtt,代码行数:27,代码来源:PublishDecoderTest.java


示例18: decode

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
public MessageDecoderResult decode(IoSession session, IoBuffer in,
        ProtocolDecoderOutput out) throws Exception {
    try {
        if (length == 0 || length == 1) {
            in.get();
            out.write("");
            return MessageDecoderResult.OK;
        }
        length++;
        byte[] result = new byte[length];
        for (int i = 0; i < length; i++) {
            result[i] = in.get();
        }
        if (0 == in.remaining()) {
            notfirstmessage = false;
        }
        String cont = new String(result, "us-ascii");
        out.write(cont.trim());
        return MessageDecoderResult.OK;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return MessageDecoderResult.OK;
}
 
开发者ID:joezhjiang,项目名称:ics-mina,代码行数:25,代码来源:MyMessageDecoder.java


示例19: decodable

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
public MessageDecoderResult decodable(IoSession session, IoBuffer in) {
	// 长度检查
	if (in.remaining() < 12) {
		return MessageDecoderResult.NEED_DATA;
	}

	// 控制码检查(未实现)
	/*byte b = in.array();
	
	if (tag == (short) 0x0001 || tag == (short) 0x8001) {
		logger.info("请求标识符:" + tag);
	} else {
		logger.error("未知的解码类型....");
		return MessageDecoderResult.NOT_OK;
	}*/

	// 数据长度检查(未实现)
	/*int len = in.getInt();
	if (in.remaining() < len) {
		return MessageDecoderResult.NEED_DATA;
	}*/
	
	//校验代码

	return MessageDecoderResult.OK;
}
 
开发者ID:xcjava,项目名称:ymesb,代码行数:27,代码来源:HyMessageDecoder.java


示例20: decodable

import org.apache.mina.filter.codec.demux.MessageDecoderResult; //导入依赖的package包/类
@Override
public MessageDecoderResult decodable(IoSession session, IoBuffer in)
{
	Context context = (Context) session.getAttribute(CONTEXT);
	
	
	//表示数据不够,需要读到新的数据后,再次调用decode()方法。
	if(context == null){
		context = new Context();
		// 跳过前4字节
		//in.skip(4); 
		//获取第一个字符用于判断是否可以被当前解码器解码
		context.dataType = in.getInt();
		if(context.dataType == BeanUtil.UPLOAD_FILE){
			System.out.println("我收到1了");
			context.strLength = in.getInt();
			context.byteStr = new byte[context.strLength];
			context.fileSize = in.getInt();
			context.byteFile = new byte[context.fileSize];
			session.setAttribute(CONTEXT, context);
			return MessageDecoderResult.OK;
		}else{
			return MessageDecoderResult.NOT_OK;
		}
	}else{
		if(context.dataType == BeanUtil.UPLOAD_FILE){
			//表示可以解码
			return MessageDecoderResult.OK;
		}else{
			//表示不能解码,会抛出异常
			return MessageDecoderResult.NOT_OK;
		}
	}
}
 
开发者ID:Xvms,项目名称:xvms,代码行数:35,代码来源:FileProtocolDecoder.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BinaryNode类代码示例发布时间:2022-05-23
下一篇:
Java HttpAdapterList类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap