public Object apply() throws IOException { Buffer sizeBytes = peekBytes(4); if (sizeBytes != null) { int size = sizeBytes.bigEndianEditor().readInt(); if (size < 8) { throw new IOException(String.format("specified frame size %d is smaller than minimum frame size", size)); } if( size > maxFrameSize ) { throw new IOException(String.format("specified frame size %d is larger than maximum frame size", size)); } // TODO: check frame min and max size.. nextDecodeAction = readFrame(size); return nextDecodeAction.apply(); } else { return null; } } };
/** * Given a long value, convert it to a byte array for marshalling. * * @param value the value to convert. * @return a new byte array that holds the big endian value of the long. */ public static byte[] toBytes(long value) { Buffer buffer = new Buffer(8); buffer.bigEndianEditor().writeLong(value); return buffer.data; }
/** * Given a long value, convert it to a byte array for marshalling. * * @param value * the value to convert. * * @return a new byte array that holds the big endian value of the long. */ public static byte[] toBytes(long value) { Buffer buffer = new Buffer(8); buffer.bigEndianEditor().writeLong(value); return buffer.data; }
@Override public void reset(int nextExpectedReadSize) { // Allocate a new Buffer to hold the incoming frame. We must write // back the frame size value before continue on to read the indicated // frame size minus the size of the AMQP frame size header value. frame = new Buffer(nextExpectedReadSize); frame.bigEndianEditor().writeInt(nextExpectedReadSize); // Reset the length to total length as we do direct write after this. frame.length = frame.data.length; } };
@Override public void reset(int nextExpectedReadSize) { // Allocate a new Buffer to hold the incoming frame. We must write // back the frame size value before continue on to read the indicated // frame size minus the size of the AMQP frame size header value. frame = new Buffer(nextExpectedReadSize); frame.bigEndianEditor().writeInt(nextExpectedReadSize); // Reset the length to total length as we do direct write after this. frame.length = frame.data.length; } };
/** * Given a long value, convert it to a byte array for marshalling. * * @param value * the value to convert. * * @return a new byte array that holds the big endian value of the long. */ public static byte[] toBytes(long value) { Buffer buffer = new Buffer(8); buffer.bigEndianEditor().writeLong(value); return buffer.data; }
/** * Converts a Binary value to a long assuming that the contained value is * stored in Big Endian encoding. * * @param value the Binary object whose payload is converted to a long. * @return a long value constructed from the bytes of the Binary instance. */ public static long toLong(Binary value) { Buffer buffer = new Buffer(value.getArray(), value.getArrayOffset(), value.getLength()); return buffer.bigEndianEditor().readLong(); }
/** * Converts a Binary value to a long assuming that the contained value is * stored in Big Endian encoding. * * @param value * the Binary object whose payload is converted to a long. * * @return a long value constructed from the bytes of the Binary instance. */ public static long toLong(Binary value) { Buffer buffer = new Buffer(value.getArray(), value.getArrayOffset(), value.getLength()); return buffer.bigEndianEditor().readLong(); }
/** * Converts a Binary value to a long assuming that the contained value is * stored in Big Endian encoding. * * @param value * the Binary object whose payload is converted to a long. * * @return a long value constructed from the bytes of the Binary instance. */ public static long toLong(Binary value) { Buffer buffer = new Buffer(value.getArray(), value.getArrayOffset(), value.getLength()); return buffer.bigEndianEditor().readLong(); }
public void run() { if(holder!=null) holder.factory.unget(); final Buffer command = baos.toBuffer(); // Update the size field. BufferEditor editor = command.buffer().bigEndianEditor(); editor.writeInt(command.length); queue().execute(new Runnable() { public void run() { transport.offer(command); } }); } });
@Override public Object unmarshal(DataInput dataIn) throws IOException { if (!magicRead) { Buffer magic = new Buffer(8); magic.readFrom(dataIn); magicRead = true; return new AmqpHeader(magic, false); } else { int size = dataIn.readInt(); if (size > maxFrameSize) { throw new AmqpProtocolException("Frame size exceeded max frame length."); } else if (size <= 0) { throw new AmqpProtocolException("Frame size value was invalid: " + size); } Buffer frame = new Buffer(size); frame.bigEndianEditor().writeInt(size); frame.readFrom(dataIn); frame.clear(); return frame; } }
@Override public Object unmarshal(DataInput dataIn) throws IOException { if (!magicRead) { Buffer magic = new Buffer(8); magic.readFrom(dataIn); magicRead = true; return new AmqpHeader(magic, false); } else { int size = dataIn.readInt(); if (size > maxFrameSize) { throw new AmqpProtocolException("Frame size exceeded max frame length."); } else if (size <= 0) { throw new AmqpProtocolException("Frame size value was invalid: " + size); } Buffer frame = new Buffer(size); frame.bigEndianEditor().writeInt(size); frame.readFrom(dataIn); frame.clear(); return frame; } }
BufferEditor editor = command.buffer().bigEndianEditor(); editor.writeInt(command.length); handler.lastRequestSize = command.length;
BufferEditor editor = command.buffer().bigEndianEditor(); editor.writeInt(command.length); handler.lastRequestSize = command.length;