@Override public int getHeadersAndPropertiesEncodeSize() { return DataConstants.SIZE_LONG + // Message ID DataConstants.SIZE_BYTE + // user id null? (userID == null ? 0 : 16) + /* address */SimpleString.sizeofNullableString(address) + DataConstants./* Type */SIZE_BYTE + DataConstants./* Durable */SIZE_BOOLEAN + DataConstants./* Expiration */SIZE_LONG + DataConstants./* Timestamp */SIZE_LONG + DataConstants./* Priority */SIZE_BYTE + /* PropertySize and Properties */checkProperties().getEncodeSize(); }
@Override public int getHeadersAndPropertiesEncodeSize() { return DataConstants.SIZE_LONG + // Message ID DataConstants.SIZE_BYTE + // user id null? (userID == null ? 0 : 16) + /* address */SimpleString.sizeofNullableString(address) + DataConstants./* Type */SIZE_BYTE + DataConstants./* Durable */SIZE_BOOLEAN + DataConstants./* Expiration */SIZE_LONG + DataConstants./* Timestamp */SIZE_LONG + DataConstants./* Priority */SIZE_BYTE + /* PropertySize and Properties */getProperties().getEncodeSize(); }
@Override public int getEncodeSize(Message record) { int encodeSize = super.getEncodeSize(record) + DataConstants.SIZE_INT; TypedProperties properties = ((AMQPMessage)record).getExtraProperties(); return encodeSize + (properties != null ? properties.getEncodeSize() : 0); }
@Override public int getEncodeSize(Message record) { int encodeSize = super.getEncodeSize(record) + DataConstants.SIZE_INT; TypedProperties properties = ((AMQPMessage)record).getExtraProperties(); return encodeSize + (properties != null ? properties.getEncodeSize() : 0); }
@Override public int getHeadersAndPropertiesEncodeSize() { return DataConstants.SIZE_LONG + // Message ID DataConstants.SIZE_BYTE + // user id null? (userID == null ? 0 : 16) + /* address */SimpleString.sizeofNullableString(address) + DataConstants./* Type */SIZE_BYTE + DataConstants./* Durable */SIZE_BOOLEAN + DataConstants./* Expiration */SIZE_LONG + DataConstants./* Timestamp */SIZE_LONG + DataConstants./* Priority */SIZE_BYTE + /* PropertySize and Properties */checkProperties().getEncodeSize(); }
@Override public int getHeadersAndPropertiesEncodeSize() { return DataConstants.SIZE_LONG + // Message ID DataConstants.SIZE_BYTE + // user id null? (userID == null ? 0 : 16) + /* address */SimpleString.sizeofNullableString(address) + DataConstants./* Type */SIZE_BYTE + DataConstants./* Durable */SIZE_BOOLEAN + DataConstants./* Expiration */SIZE_LONG + DataConstants./* Timestamp */SIZE_LONG + DataConstants./* Priority */SIZE_BYTE + /* PropertySize and Properties */getProperties().getEncodeSize(); }
@Override public int getHeadersAndPropertiesEncodeSize() { return DataConstants.SIZE_LONG + // Message ID DataConstants.SIZE_BYTE + // user id null? (userID == null ? 0 : 16) + /* address */SimpleString.sizeofNullableString(address) + DataConstants./* Type */SIZE_BYTE + DataConstants./* Durable */SIZE_BOOLEAN + DataConstants./* Expiration */SIZE_LONG + DataConstants./* Timestamp */SIZE_LONG + DataConstants./* Priority */SIZE_BYTE + /* PropertySize and Properties */getProperties().getEncodeSize(); }
@Override public int getHeadersAndPropertiesEncodeSize() { return DataConstants.SIZE_LONG + // Message ID DataConstants.SIZE_BYTE + // user id null? (userID == null ? 0 : 16) + /* address */SimpleString.sizeofNullableString(address) + DataConstants./* Type */SIZE_BYTE + DataConstants./* Durable */SIZE_BOOLEAN + DataConstants./* Expiration */SIZE_LONG + DataConstants./* Timestamp */SIZE_LONG + DataConstants./* Priority */SIZE_BYTE + /* PropertySize and Properties */checkProperties().getEncodeSize(); }
@Override public int getHeadersAndPropertiesEncodeSize() { return DataConstants.SIZE_LONG + // Message ID DataConstants.SIZE_BYTE + // user id null? (userID == null ? 0 : 16) + /* address */SimpleString.sizeofNullableString(address) + DataConstants./* Type */SIZE_BYTE + DataConstants./* Durable */SIZE_BOOLEAN + DataConstants./* Expiration */SIZE_LONG + DataConstants./* Timestamp */SIZE_LONG + DataConstants./* Priority */SIZE_BYTE + /* PropertySize and Properties */checkProperties().getEncodeSize(); }
private static byte[] toAMQMessageMapType(final ActiveMQBuffer buffer, final boolean isCompressed) throws IOException { byte[] bytes = null; //it could be a null map if (buffer.readableBytes() > 0) { TypedProperties mapData = new TypedProperties(); mapData.decode(buffer.byteBuf()); Map<String, Object> map = mapData.getMap(); ByteArrayOutputStream out = new ByteArrayOutputStream(mapData.getEncodeSize()); OutputStream os = out; if (isCompressed) { os = new DeflaterOutputStream(os, true); } try (DataOutputStream dataOut = new DataOutputStream(os)) { MarshallingSupport.marshalPrimitiveMap(map, dataOut); dataOut.flush(); } bytes = out.toByteArray(); } return bytes; }
/** Sub classes must add the first short as the protocol-id */ @Override public void encode(ActiveMQBuffer buffer, Message record) { super.encode(buffer, record); TypedProperties properties = ((AMQPMessage)record).getExtraProperties(); if (properties == null) { buffer.writeInt(0); } else { buffer.writeInt(properties.getEncodeSize()); properties.encode(buffer.byteBuf()); } }
/** Sub classes must add the first short as the protocol-id */ @Override public void encode(ActiveMQBuffer buffer, Message record) { super.encode(buffer, record); TypedProperties properties = ((AMQPMessage)record).getExtraProperties(); if (properties == null) { buffer.writeInt(0); } else { buffer.writeInt(properties.getEncodeSize()); properties.encode(buffer.byteBuf()); } }
@Test public void testEncodedSizeAfterClearIsSameAsNewTypedProperties() throws Exception { TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(SimpleString.toSimpleString("helllllloooooo"), SimpleString.toSimpleString("raaaaaaaaaaaaaaaaaaaaaaaa")); props.clear(); assertEquals(new TypedProperties().getEncodeSize(), props.getEncodeSize()); }
private static void assertEqualsTypeProperties(final TypedProperties expected, final TypedProperties actual) { Assert.assertNotNull(expected); Assert.assertNotNull(actual); Assert.assertEquals(expected.getEncodeSize(), actual.getEncodeSize()); Assert.assertEquals(expected.getPropertyNames(), actual.getPropertyNames()); Iterator<SimpleString> iterator = actual.getPropertyNames().iterator(); while (iterator.hasNext()) { SimpleString key = iterator.next(); Object expectedValue = expected.getProperty(key); Object actualValue = actual.getProperty(key); if (expectedValue instanceof byte[] && actualValue instanceof byte[]) { byte[] expectedBytes = (byte[]) expectedValue; byte[] actualBytes = (byte[]) actualValue; Assert.assertArrayEquals(expectedBytes, actualBytes); } else { Assert.assertEquals(expectedValue, actualValue); } } }
@Test public void testCopyContructor() throws Exception { props.putSimpleStringProperty(key, RandomUtil.randomSimpleString()); TypedProperties copy = new TypedProperties(props); Assert.assertEquals(props.getEncodeSize(), copy.getEncodeSize()); Assert.assertEquals(props.getPropertyNames(), copy.getPropertyNames()); Assert.assertTrue(copy.containsProperty(key)); Assert.assertEquals(props.getProperty(key), copy.getProperty(key)); }
@Test public void testEncodeDecodeEmpty() throws Exception { TypedProperties emptyProps = new TypedProperties(); ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(1024); emptyProps.encode(buffer.byteBuf()); Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex()); TypedProperties decodedProps = new TypedProperties(); decodedProps.decode(buffer.byteBuf()); TypedPropertiesTest.assertEqualsTypeProperties(emptyProps, decodedProps); }
@Test public void testEncodeDecode() throws Exception { props.putByteProperty(RandomUtil.randomSimpleString(), RandomUtil.randomByte()); props.putBytesProperty(RandomUtil.randomSimpleString(), RandomUtil.randomBytes()); props.putBytesProperty(RandomUtil.randomSimpleString(), null); props.putBooleanProperty(RandomUtil.randomSimpleString(), RandomUtil.randomBoolean()); props.putShortProperty(RandomUtil.randomSimpleString(), RandomUtil.randomShort()); props.putIntProperty(RandomUtil.randomSimpleString(), RandomUtil.randomInt()); props.putLongProperty(RandomUtil.randomSimpleString(), RandomUtil.randomLong()); props.putFloatProperty(RandomUtil.randomSimpleString(), RandomUtil.randomFloat()); props.putDoubleProperty(RandomUtil.randomSimpleString(), RandomUtil.randomDouble()); props.putCharProperty(RandomUtil.randomSimpleString(), RandomUtil.randomChar()); props.putSimpleStringProperty(RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString()); props.putSimpleStringProperty(RandomUtil.randomSimpleString(), null); SimpleString keyToRemove = RandomUtil.randomSimpleString(); props.putSimpleStringProperty(keyToRemove, RandomUtil.randomSimpleString()); ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(1024); props.encode(buffer.byteBuf()); Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex()); TypedProperties decodedProps = new TypedProperties(); decodedProps.decode(buffer.byteBuf()); TypedPropertiesTest.assertEqualsTypeProperties(props, decodedProps); buffer.clear(); // After removing a property, you should still be able to encode the Property props.removeProperty(keyToRemove); props.encode(buffer.byteBuf()); Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex()); }