Package org.jboss.netty.buffer

Examples of org.jboss.netty.buffer.ChannelBuffer.array()


    @Test
    public void testGenChor() throws Exception {
        ChorBuilder chorBuilder = new ChorBuilder("10,0,motor,1,20,0,0,0,led,2,0,238,0,2,led,1,250,0,0,3,led,2,0,0,0", 5);
        ChannelBuffer buffer = chorBuilder.build();
        System.out.println("length: " + buffer.readableBytes());
        System.out.println(Hex.encodeHexString(buffer.array()));
    }
}
View Full Code Here


        // There's enough bytes in the buffer. Read it.
        ChannelBuffer payload = buf.readBytes(length);

        // Successfully decoded a frame.
        // Return a TaskMessage object
        return new TaskMessage(task,payload.array());
    }
}
View Full Code Here

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
      // Get handle from create response
      ChannelBuffer buf = (ChannelBuffer) e.getMessage();
      XDR rsp = new XDR(buf.array());
      if (rsp.getBytes().length == 0) {
        LOG.info("rsp length is zero, why?");
        return;
      }
      LOG.info("rsp length=" + rsp.getBytes().length);
View Full Code Here

        int size = message.getSerializedSize();
        ChannelBuffer buffer = new BigEndianHeapChannelBuffer(4 + size + 4);
        buffer.writeBytes("RPC0".getBytes());
        int writerIndex = buffer.writerIndex();
        CodedOutputStream output = CodedOutputStream.newInstance(
                buffer.array(), buffer.writerIndex(), buffer.writableBytes() - 4);
        message.writeTo(output);
        output.checkNoSpaceLeft();

        buffer.writerIndex(writerIndex + size);
        Adler32 checksum = new Adler32();
View Full Code Here

        message.writeTo(output);
        output.checkNoSpaceLeft();

        buffer.writerIndex(writerIndex + size);
        Adler32 checksum = new Adler32();
        checksum.update(buffer.array(), buffer.arrayOffset(), buffer.readableBytes());
        buffer.writeInt((int) checksum.getValue());
        return buffer;
    }
}
View Full Code Here

            ChannelBuffer buffer = (ChannelBuffer) obj;
            if (buffer.readableBytes() > 8) {
                String version = buffer.toString(buffer.readerIndex(), 4, Charset.defaultCharset());
                if (version.equals("RPC0")) {
                    Adler32 adler32 = new Adler32();
                    adler32.update(buffer.array(),
                            buffer.arrayOffset() + buffer.readerIndex(),
                            buffer.readableBytes() - 4);
                    buffer.markReaderIndex();
                    buffer.readerIndex(buffer.writerIndex() - 4);
                    int checksum = buffer.readInt();
View Full Code Here

                    buffer.readerIndex(buffer.writerIndex() - 4);
                    int checksum = buffer.readInt();
                    if (checksum == (int)adler32.getValue()) {
                        buffer.resetReaderIndex();
                        RpcMessage message = RpcMessage.newBuilder().mergeFrom(
                                buffer.array(),
                                buffer.arrayOffset() + buffer.readerIndex() + 4,
                                buffer.readableBytes() - 8).build();
                        return message;
                    }
                }
View Full Code Here

        buffer.writeBytes(name.getBytes());
        buffer.writeZero(1);
        buffer.writeBytes(message.toByteArray());

        Adler32 checksum = new Adler32();
        checksum.update(buffer.array(), buffer.arrayOffset(), buffer.readableBytes());
        buffer.writeInt((int) checksum.getValue());

        return buffer;
    }
}
View Full Code Here

            String typeName = buffer.toString(buffer.readerIndex(), nameLen - 1,
                    Charset.defaultCharset());
            buffer.readerIndex(buffer.readerIndex() + nameLen);
            Message prototype = knownTypes.get(typeName);
            if (prototype != null) {
                return prototype.newBuilderForType().mergeFrom(buffer.array(),
                        buffer.arrayOffset() + buffer.readerIndex(),
                        buffer.readableBytes() - 4).build();
            }
        }
        return obj;
View Full Code Here

    Event event = (Event)msg;
    if(event.getType() == Events.SESSION_MESSAGE)
    {
      ChannelBuffer buffer = (ChannelBuffer)event.getSource();
      LOG.trace("BinaryArray with size:{} Received.", buffer.readableBytes());
      ByteArrayInputStream bis = new ByteArrayInputStream(buffer.array());
      event.setSource(bis);
    }
    return event;
  }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.