Java Code Examples for org.apache.qpid.proton.amqp.Binary#asByteBuffer()
The following examples show how to use
org.apache.qpid.proton.amqp.Binary#asByteBuffer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testEncodeDecodeSymbolArrayUsingPutObject() { Symbol symbol1 = Symbol.valueOf("testRoundtripSymbolArray1"); Symbol symbol2 = Symbol.valueOf("testRoundtripSymbolArray2"); Symbol[] input = new Symbol[]{symbol1, symbol2}; Data data1 = new DataImpl(); data1.putObject(input); Binary encoded = data1.encode(); encoded.asByteBuffer(); Data data2 = new DataImpl(); data2.decode(encoded.asByteBuffer()); assertEquals("unexpected array length", 2, data2.getArray()); assertEquals("unexpected array length", Data.DataType.SYMBOL, data2.getArrayType()); Object[] array = data2.getJavaArray(); assertArrayEquals("Array not as expected", input, array); }
Example 2
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * Test that setting then getting binary as the correlationId returns the expected value * and sets the correlation id field as expected on the underlying AMQP message * @throws Exception if unexpected error */ @Test public void testSetGetCorrelationIdOnNewMessageWithBinary() throws Exception { Binary testCorrelationId = createBinaryId(); ByteBuffer buf = testCorrelationId.asByteBuffer(); byte[] bytes = new byte[buf.remaining()]; buf.get(bytes); String converted = "ID:AMQP_BINARY:" + AmqpMessageIdHelper.convertBinaryToHexString(bytes); AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade(); amqpMessageFacade.setCorrelationId(converted); assertEquals("Unexpected correlationId value on underlying AMQP message", testCorrelationId, amqpMessageFacade.getProperties().getCorrelationId()); assertEquals("Expected correlationId not returned", converted, amqpMessageFacade.getCorrelationId()); }
Example 3
Source File: DataImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testEncodeDecodeSymbolArrayUsingPutArray() { Symbol symbol1 = Symbol.valueOf("testRoundtripSymbolArray1"); Symbol symbol2 = Symbol.valueOf("testRoundtripSymbolArray2"); Data data1 = new DataImpl(); data1.putArray(false, Data.DataType.SYMBOL); data1.enter(); data1.putSymbol(symbol1); data1.putSymbol(symbol2); data1.exit(); Binary encoded = data1.encode(); encoded.asByteBuffer(); Data data2 = new DataImpl(); data2.decode(encoded.asByteBuffer()); assertEquals("unexpected array length", 2, data2.getArray()); assertEquals("unexpected array length", Data.DataType.SYMBOL, data2.getArrayType()); Object[] array = data2.getJavaArray(); assertNotNull("Array should not be null", array); assertEquals("Expected a Symbol array", Symbol[].class, array.getClass()); assertEquals("unexpected array length", 2, array.length); assertEquals("unexpected value", symbol1, array[0]); assertEquals("unexpected value", symbol2, array[1]); }
Example 4
Source File: DataImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private byte[] doEncodeDecodeBinaryTestImpl(byte[] payload) { Data data = new DataImpl(); data.putBinary(payload); Binary encoded = data.encode(); ByteBuffer byteBuffer = encoded.asByteBuffer(); Data data2 = new DataImpl(); long decodeResult = data2.decode(byteBuffer); assertTrue(Long.toString(decodeResult), decodeResult > 0); assertEquals("unexpected type", Data.DataType.BINARY, data2.type()); return data2.getBinary().getArray(); }
Example 5
Source File: AmqpDataFramer.java From qpid-jms with Apache License 2.0 | 4 votes |
public static byte[] encodeFrame(FrameType type, int channel, DescribedType describedType, Binary payload) { ByteBuffer buffer = ByteBuffer.allocate(INITIAL_CAPACITY); buffer.position(FRAME_HEADER_SIZE); // leave hole for frame header if (describedType != null) { Data frameBody = Data.Factory.create(); frameBody.putDescribedType(describedType); long encodedLength = frameBody.encode(buffer); if(encodedLength > buffer.capacity() - FRAME_HEADER_SIZE) { throw new IllegalStateException("Performative encoding exceeded buffer size"); } } if(payload != null) { ByteBuffer framePayload = payload.asByteBuffer(); if(framePayload.remaining() > buffer.remaining()) { ByteBuffer oldBuffer = buffer; buffer = ByteBuffer.allocate(oldBuffer.position() + framePayload.remaining()); oldBuffer.flip(); buffer.put(oldBuffer); } buffer.put(framePayload); } int frameSize = buffer.position(); buffer.rewind(); buffer.putInt(frameSize); buffer.put(FRAME_PREAMBLE_SIZE_IN_FOUR_BYTE_WORDS); buffer.put((byte)type.ordinal()); buffer.putShort((short)channel); byte[] target = new byte[frameSize]; buffer.rewind(); buffer.get(target, 0, frameSize); return target; }