Example #1
0
  public QueryRequest(ByteBuf buffer) {
    super(buffer, kXR_query);
    reqcode = buffer.getUnsignedShort(4);
    fhandle = buffer.getInt(8);
    int alen = buffer.getInt(20);

    /* The protocol spec doesn't state anything about trailing zeros in args,
     * however the xrdfs client sends zero terminated paths.
     */
    args = NULL_CHARACTER.trimTrailingFrom(buffer.toString(24, alen, US_ASCII));
  }
Example #2
0
  @Test(timeout = 1000)
  public void a() {
    ByteBuf buf = Unpooled.buffer(4);
    buf.setInt(0, 1);
    System.out.format("%08x%n", buf.getInt(0));
    ByteBuf leBuf = buf.order(ByteOrder.LITTLE_ENDIAN);
    // 打印出 '01000000'
    System.out.format("%08x%n", leBuf.getInt(0));

    assert buf != leBuf;
    assert buf == buf.order(ByteOrder.BIG_ENDIAN);
  }
 @Override
 protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
   if (in.readableBytes() < 4 * Integer.SIZE / Byte.SIZE) {
     return;
   }
   int numPayloads = in.getInt(in.readerIndex() + 3 * Integer.SIZE / Byte.SIZE);
   int index = 4 * Integer.SIZE / Byte.SIZE;
   for (int i = 0; i < numPayloads; i++) {
     if (in.readableBytes() < index + Integer.SIZE / Byte.SIZE) {
       return;
     }
     int size = in.getInt(in.readerIndex() + index);
     index += Integer.SIZE / Byte.SIZE + size;
     if (in.readableBytes() < index) {
       return;
     }
   }
   int sender = in.readInt();
   int dest = in.readInt();
   int msgType = in.readInt();
   numPayloads = in.readInt();
   Msg msg = new Msg(msgType);
   msg.setSender(sender);
   msg.setDest(dest);
   for (int i = 0; i < numPayloads; i++) {
     int size = in.readInt();
     if (size > 0) {
       ByteBuffer buffer = ByteBuffer.allocate(size);
       in.readBytes(buffer);
       buffer.rewind();
       msg.addPayload(buffer);
     } else {
       msg.addPayload(null);
     }
   }
   out.add(msg);
 }
Example #4
0
 @Override
 public int getInt(int index) {
   return buf.getInt(index);
 }
Example #5
0
 /**
  * Returns the {@code int} at position {@code pos} in the Buffer.
  *
  * @throws IndexOutOfBoundsException if the specified {@code pos} is less than {@code 0} or {@code
  *     pos + 4} is greater than the length of the Buffer.
  */
 public int getInt(int pos) {
   return buffer.getInt(pos);
 }
 @Override
 public int getInt(int var1) {
   return a.getInt(var1);
 }