コード例 #1
0
ファイル: TestCodeC.java プロジェクト: ericzuobin/nettybook
  public NettyMessage decode(ByteBuf in) throws Exception {
    NettyMessage message = new NettyMessage();
    Header header = new Header();
    header.setCrcCode(in.readInt());
    header.setLength(in.readInt());
    header.setSessionID(in.readLong());
    header.setType(in.readByte());
    header.setPriority(in.readByte());

    int size = in.readInt();
    if (size > 0) {
      Map<String, Object> attch = new HashMap<String, Object>(size);
      int keySize = 0;
      byte[] keyArray = null;
      String key = null;
      for (int i = 0; i < size; i++) {
        keySize = in.readInt();
        keyArray = new byte[keySize];
        in.readBytes(keyArray);
        key = new String(keyArray, "UTF-8");
        attch.put(key, marshallingDecoder.decode(in));
      }
      keyArray = null;
      key = null;
      header.setAttachment(attch);
    }
    if (in.readableBytes() > 4) {
      message.setBody(marshallingDecoder.decode(in));
    }
    message.setHeader(header);
    return message;
  }
コード例 #2
0
ファイル: TestCodeC.java プロジェクト: ericzuobin/nettybook
 public NettyMessage getMessage() {
   NettyMessage nettyMessage = new NettyMessage();
   Header header = new Header();
   header.setLength(123);
   header.setSessionID(99999);
   header.setType((byte) 1);
   header.setPriority((byte) 7);
   Map<String, Object> attachment = new HashMap<String, Object>();
   for (int i = 0; i < 10; i++) {
     attachment.put("ciyt --> " + i, "Administrator " + i);
   }
   header.setAttachment(attachment);
   nettyMessage.setHeader(header);
   nettyMessage.setBody("abcdefg-----------------------AAAAAA");
   return nettyMessage;
 }