diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2006-12-12 17:51:51 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2006-12-12 17:51:51 +0000 |
| commit | 853cf049a66ed4fa727bd2c7c46e0beabeb33a33 (patch) | |
| tree | 37fdacf14af9a3073cdc8f99b777327b826b8833 /java/common/src | |
| parent | b10ee442673d6d9c8abb46bd7a0606364930130d (diff) | |
| download | qpid-python-853cf049a66ed4fa727bd2c7c46e0beabeb33a33.tar.gz | |
QPID-164
JMSMapMessage.java - fixed incorrect exceptions and return values. Data now sent as a Bytes message.
MapMessageTest.java - updated to be more through with the testing of the returned message
EncodingUtils.java - added unsignedIntegerLength()
FieldTableFactory.java - removed specific PropertyFieldTable reference
PropertyFieldTable.java - fixed encoding issues that were causing BufferOverflow errors.
PropertyFieldTableTest.java - added test to ensure that the encoding size is correct for ALL types.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@486254 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common/src')
4 files changed, 330 insertions, 84 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java b/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java index 2f791ea541..0c0b201174 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java +++ b/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java @@ -100,7 +100,7 @@ public class EncodingUtils public static int encodedContentLength(Content table) { - // TODO: New Content class required for AMQP 0-9. + // TODO: New Content class required for AMQP 0-9. return 0; } @@ -114,7 +114,7 @@ public class EncodingUtils { encodedString[i] = (byte) cha[i]; } - writeBytes(buffer,encodedString); + writeBytes(buffer, encodedString); } else { @@ -199,6 +199,12 @@ public class EncodingUtils } } + + public static long unsignedIntegerLength() + { + return 4; + } + public static void writeUnsignedInteger(ByteBuffer buffer, long l) { // TODO: Is this comparison safe? Do I need to cast RHS to long? @@ -233,7 +239,7 @@ public class EncodingUtils public static void writeContentBytes(ByteBuffer buffer, Content content) { - // TODO: New Content class required for AMQP 0-9. + // TODO: New Content class required for AMQP 0-9. } public static void writeBooleans(ByteBuffer buffer, boolean[] values) @@ -302,8 +308,8 @@ public class EncodingUtils public static Content readContent(ByteBuffer buffer) throws AMQFrameDecodingException { - // TODO: New Content class required for AMQP 0-9. - return null; + // TODO: New Content class required for AMQP 0-9. + return null; } public static String readShortString(ByteBuffer buffer) @@ -602,4 +608,9 @@ public class EncodingUtils buffer.put((byte) 0); } } + + public static long encodedCharacterLength() + { + return encodedShortStringLength("c"); + } } diff --git a/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java b/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java index 1ec57da35b..b1fcd8a20b 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java +++ b/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java @@ -34,7 +34,7 @@ public class FieldTableFactory return new PropertyFieldTable(byteBuffer, length); } - public static PropertyFieldTable newFieldTable(String text) + public static FieldTable newFieldTable(String text) { return new PropertyFieldTable(text); } diff --git a/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java b/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java index 48ca34abfe..f367156e73 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java +++ b/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java @@ -79,7 +79,7 @@ public class PropertyFieldTable implements FieldTable, Map private LinkedHashMap<String, Object> _properties; private LinkedHashMap<String, String> _propertyNamesTypeMap; - private long _encodedSize = 0; + private long _encodedSize = 0;//EncodingUtils.unsignedIntegerLength(); public PropertyFieldTable() { @@ -138,7 +138,7 @@ public class PropertyFieldTable implements FieldTable, Map public Boolean getBoolean(String string) { Object o = get(string, BOOLEAN_PROPERTY_PREFIX); - if (o != null) + if (o != null && o instanceof Boolean) { return (Boolean) o; } @@ -209,7 +209,7 @@ public class PropertyFieldTable implements FieldTable, Map } else { - return null; + return null; //Float.valueOf(null); ??? } } @@ -235,7 +235,43 @@ public class PropertyFieldTable implements FieldTable, Map } else { - return null; + String type = _propertyNamesTypeMap.get(string); + + if (type == null) + { + return null; + } + else + { + char itype = type.charAt(0); + + Object value = _properties.get(string); + + switch (itype) + { + case STRING_PROPERTY_PREFIX: + case BYTES_PROPERTY_PREFIX: + return null; + default: + case BYTE_PROPERTY_PREFIX: + case BOOLEAN_PROPERTY_PREFIX: + case SHORT_PROPERTY_PREFIX: + case INT_PROPERTY_PREFIX: + case LONG_PROPERTY_PREFIX: + case FLOAT_PROPERTY_PREFIX: + case DOUBLE_PROPERTY_PREFIX: + return String.valueOf(value); + case CHAR_PROPERTY_PREFIX: + if (value == null) + { + throw new NullPointerException("null char cannot be converted to String"); + } + else + { + return String.valueOf(value); + } + } + } } } @@ -902,6 +938,8 @@ public class PropertyFieldTable implements FieldTable, Map } EncodingUtils.writeUnsignedInteger(buffer, _encodedSize); + //EncodingUtils.writeLong(buffer, _encodedSize); + putDataInBuffer(buffer); } @@ -959,7 +997,17 @@ public class PropertyFieldTable implements FieldTable, Map String propertyName = key.substring(1); char propertyPrefix = _propertyNamesTypeMap.get(propertyName).charAt(0); - if (value != null) + if (_logger.isDebugEnabled()) + { + _logger.debug("Put:" + propertyName + + " encoding Now:" + _encodedSize + + " name size= " + EncodingUtils.encodedShortStringLength(propertyName) + + " value size= " + getEncodingSize(key, value)); + } + + // This prevents the item from being sent. + // JMS needs these propertyNames for lookups. + //if (value != null) { //Add the size of the propertyName _encodedSize += EncodingUtils.encodedShortStringLength(propertyName); @@ -972,6 +1020,11 @@ public class PropertyFieldTable implements FieldTable, Map _encodedSize += getEncodingSize(key, value); } + if (_logger.isDebugEnabled()) + { + _logger.debug("Put: new encodingSize " + _encodedSize); + } + _properties.put((String) propertyName, value); return previous; @@ -1046,6 +1099,7 @@ public class PropertyFieldTable implements FieldTable, Map private void putDataInBuffer(ByteBuffer buffer) { + final Iterator it = _properties.entrySet().iterator(); //If there are values then write out the encoded Size... could check _encodedSize != 0 @@ -1054,84 +1108,113 @@ public class PropertyFieldTable implements FieldTable, Map while (it.hasNext()) { + Map.Entry me = (Map.Entry) it.next(); String propertyName = (String) me.getKey(); //The type value char propertyPrefix = _propertyNamesTypeMap.get(propertyName).charAt(0); - //The actual param name skipping type - EncodingUtils.writeShortStringBytes(buffer, propertyName); Object value = me.getValue(); - - switch (propertyPrefix) + try { - case BOOLEAN_PROPERTY_PREFIX: - buffer.put((byte) BOOLEAN_PROPERTY_PREFIX); - EncodingUtils.writeBoolean(buffer, (Boolean) value); - break; - case BYTE_PROPERTY_PREFIX: - buffer.put((byte) BYTE_PROPERTY_PREFIX); - EncodingUtils.writeByte(buffer, (Byte) value); - break; - case SHORT_PROPERTY_PREFIX: - buffer.put((byte) SHORT_PROPERTY_PREFIX); - EncodingUtils.writeShort(buffer, (Short) value); - break; - case INT_PROPERTY_PREFIX: - buffer.put((byte) INT_PROPERTY_PREFIX); - EncodingUtils.writeInteger(buffer, (Integer) value); - break; - case AMQP_UNSIGNEDINT_PROPERTY_PREFIX: // Currently we don't create these - buffer.put((byte) AMQP_UNSIGNEDINT_PROPERTY_PREFIX); - EncodingUtils.writeUnsignedInteger(buffer, (Long) value); - break; - case LONG_PROPERTY_PREFIX: - buffer.put((byte) LONG_PROPERTY_PREFIX); - EncodingUtils.writeLong(buffer, (Long) value); - break; - case FLOAT_PROPERTY_PREFIX: - buffer.put((byte) FLOAT_PROPERTY_PREFIX); - EncodingUtils.writeFloat(buffer, (Float) value); - break; - case DOUBLE_PROPERTY_PREFIX: - buffer.put((byte) DOUBLE_PROPERTY_PREFIX); - EncodingUtils.writeDouble(buffer, (Double) value); - break; + if (_logger.isDebugEnabled()) + { + _logger.debug("Writing Property:" + propertyName + + " Type:" + propertyPrefix + + " Value:" + value); + _logger.debug("Buffer Position:" + buffer.position() + + " Remaining:" + buffer.remaining()); + } - case AMQP_WIDE_STRING_PROPERTY_PREFIX: - //case AMQP_STRING_PROPERTY_PREFIX: - case STRING_PROPERTY_PREFIX: - // TODO: look at using proper charset encoder - buffer.put((byte) STRING_PROPERTY_PREFIX); - EncodingUtils.writeLongStringBytes(buffer, (String) value); - break; + //The actual param name skipping type + EncodingUtils.writeShortStringBytes(buffer, propertyName); - //case AMQP_ASCII_STRING_PROPERTY_PREFIX: - case CHAR_PROPERTY_PREFIX: - // TODO: look at using proper charset encoder - buffer.put((byte) CHAR_PROPERTY_PREFIX); - EncodingUtils.writeShortStringBytes(buffer, "" + (Character) value); - break; - case BYTES_PROPERTY_PREFIX: - buffer.put((byte) BYTES_PROPERTY_PREFIX); - EncodingUtils.writeBytes(buffer, (byte[]) value); - break; + switch (propertyPrefix) + { - case XML_PROPERTY_PREFIX: - // Encode as XML - buffer.put((byte) XML_PROPERTY_PREFIX); - EncodingUtils.writeLongStringBytes(buffer, valueAsXML(propertyPrefix + propertyName, value)); - break; - default: + case BOOLEAN_PROPERTY_PREFIX: + buffer.put((byte) BOOLEAN_PROPERTY_PREFIX); + EncodingUtils.writeBoolean(buffer, (Boolean) value); + break; + case BYTE_PROPERTY_PREFIX: + buffer.put((byte) BYTE_PROPERTY_PREFIX); + EncodingUtils.writeByte(buffer, (Byte) value); + break; + case SHORT_PROPERTY_PREFIX: + buffer.put((byte) SHORT_PROPERTY_PREFIX); + EncodingUtils.writeShort(buffer, (Short) value); + break; + case INT_PROPERTY_PREFIX: + buffer.put((byte) INT_PROPERTY_PREFIX); + EncodingUtils.writeInteger(buffer, (Integer) value); + break; + case AMQP_UNSIGNEDINT_PROPERTY_PREFIX: // Currently we don't create these + buffer.put((byte) AMQP_UNSIGNEDINT_PROPERTY_PREFIX); + EncodingUtils.writeUnsignedInteger(buffer, (Long) value); + break; + case LONG_PROPERTY_PREFIX: + buffer.put((byte) LONG_PROPERTY_PREFIX); + EncodingUtils.writeLong(buffer, (Long) value); + break; + case FLOAT_PROPERTY_PREFIX: + buffer.put((byte) FLOAT_PROPERTY_PREFIX); + EncodingUtils.writeFloat(buffer, (Float) value); + break; + case DOUBLE_PROPERTY_PREFIX: + buffer.put((byte) DOUBLE_PROPERTY_PREFIX); + EncodingUtils.writeDouble(buffer, (Double) value); + break; + + case AMQP_WIDE_STRING_PROPERTY_PREFIX: + //case AMQP_STRING_PROPERTY_PREFIX: + case STRING_PROPERTY_PREFIX: + // TODO: look at using proper charset encoder + buffer.put((byte) STRING_PROPERTY_PREFIX); + EncodingUtils.writeLongStringBytes(buffer, (String) value); + break; + + //case AMQP_ASCII_STRING_PROPERTY_PREFIX: + case CHAR_PROPERTY_PREFIX: + // TODO: look at using proper charset encoder + buffer.put((byte) CHAR_PROPERTY_PREFIX); + EncodingUtils.writeShortStringBytes(buffer, "" + (Character) value); + break; + + case BYTES_PROPERTY_PREFIX: + buffer.put((byte) BYTES_PROPERTY_PREFIX); + EncodingUtils.writeBytes(buffer, (byte[]) value); + break; + + case XML_PROPERTY_PREFIX: + // Encode as XML + buffer.put((byte) XML_PROPERTY_PREFIX); + EncodingUtils.writeLongStringBytes(buffer, valueAsXML(propertyPrefix + propertyName, value)); + break; + default: + { + // Should never get here + throw new IllegalArgumentException("Key '" + propertyName + "': Unsupported type in field table, type: " + ((value == null) ? "null-object" : value.getClass())); + } + } + } + catch (Exception e) + { + if (_logger.isDebugEnabled()) { - // Should never get here - throw new IllegalArgumentException("Key '" + propertyName + "': Unsupported type in field table, type: " + ((value == null) ? "null-object" : value.getClass())); + _logger.debug("Exception thrown:" + e); + _logger.debug("Writing Property:" + propertyName + + " Type:" + propertyPrefix + + " Value:" + value); + _logger.debug("Buffer Position:" + buffer.position() + + " Remaining:" + buffer.remaining()); } + throw new RuntimeException(e); } } + } @@ -1207,6 +1290,12 @@ public class PropertyFieldTable implements FieldTable, Map if (type != XML_PROPERTY_PREFIX) { setObject(key, value); + if (value == null) + { + _logger.debug("setFromBuffer: value is null for key:" + key); + _propertyNamesTypeMap.put(key, "" + type); + _properties.put(key, null); + } } } @@ -1224,47 +1313,47 @@ public class PropertyFieldTable implements FieldTable, Map */ private static int getEncodingSize(String name, Object value) { - int encodingSize; + int encodingSize = 1; // Initialy 1 to cover the char prefix char propertyPrefix = name.charAt(0); switch (propertyPrefix) { case BOOLEAN_PROPERTY_PREFIX: - encodingSize = 1 + EncodingUtils.encodedBooleanLength(); + encodingSize += EncodingUtils.encodedBooleanLength(); break; case BYTE_PROPERTY_PREFIX: - encodingSize = 1 + EncodingUtils.encodedByteLength(); + encodingSize += EncodingUtils.encodedByteLength(); break; case SHORT_PROPERTY_PREFIX: - encodingSize = 1 + EncodingUtils.encodedShortLength(); + encodingSize += EncodingUtils.encodedShortLength(); break; case INT_PROPERTY_PREFIX: - encodingSize = 1 + EncodingUtils.encodedIntegerLength(); + encodingSize += EncodingUtils.encodedIntegerLength(); break; case LONG_PROPERTY_PREFIX: - encodingSize = 1 + EncodingUtils.encodedLongLength(); + encodingSize += EncodingUtils.encodedLongLength(); break; case FLOAT_PROPERTY_PREFIX: - encodingSize = 1 + EncodingUtils.encodedFloatLength(); + encodingSize += EncodingUtils.encodedFloatLength(); break; case DOUBLE_PROPERTY_PREFIX: - encodingSize = 1 + EncodingUtils.encodedDoubleLength(); + encodingSize += EncodingUtils.encodedDoubleLength(); break; case AMQP_WIDE_STRING_PROPERTY_PREFIX: //case AMQP_STRING_PROPERTY_PREFIX: case STRING_PROPERTY_PREFIX: - encodingSize = 1 + EncodingUtils.encodedLongStringLength((String) value); + encodingSize += EncodingUtils.encodedLongStringLength((String) value); break; //case AMQP_ASCII_STRING_PROPERTY_PREFIX: case CHAR_PROPERTY_PREFIX: - encodingSize = 1 + EncodingUtils.encodedShortStringLength("" + (Character) value); + encodingSize += EncodingUtils.encodedShortStringLength("" + (Character) value); break; case BYTES_PROPERTY_PREFIX: - encodingSize = 1 + ((byte[]) value).length; + encodingSize += 1 + ((byte[]) value).length; break; case XML_PROPERTY_PREFIX: - encodingSize = 1 + EncodingUtils.encodedLongStringLength(valueAsXML(name, value)); + encodingSize += EncodingUtils.encodedLongStringLength(valueAsXML(name, value)); break; default: //encodingSize = 1 + EncodingUtils.encodedLongStringLength(String.valueOf(value)); diff --git a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java index 5166168b04..e41487ba4b 100644 --- a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java +++ b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java @@ -65,7 +65,14 @@ public class PropertyFieldTableTest extends TestCase { PropertyFieldTable table1 = new PropertyFieldTable(); table1.setBoolean("value", true); + //Test Getting right value back Assert.assertEquals((Boolean) true, table1.getBoolean("value")); + + //Looking up an invalid value returns null + Assert.assertTrue(table1.getBoolean("Rubbish") == null); + + //Try reading value as a string + Assert.assertEquals("true", table1.getString("value")); } public void testByteLookup() @@ -73,6 +80,12 @@ public class PropertyFieldTableTest extends TestCase PropertyFieldTable table1 = new PropertyFieldTable(); table1.setByte("value", (byte) 1); Assert.assertEquals((Byte) (byte) 1, table1.getByte("value")); + + //Looking up an invalid value returns null + Assert.assertTrue(table1.getByte("Rubbish") == null); + + //Try reading value as a string + Assert.assertEquals("1", table1.getString("value")); } public void testShortLookup() @@ -80,6 +93,12 @@ public class PropertyFieldTableTest extends TestCase PropertyFieldTable table1 = new PropertyFieldTable(); table1.setShort("value", Short.MAX_VALUE); Assert.assertEquals((Short) Short.MAX_VALUE, table1.getShort("value")); + + //Looking up an invalid value returns null + Assert.assertTrue(table1.getShort("Rubbish") == null); + + //Try reading value as a string + Assert.assertEquals("" + Short.MAX_VALUE, table1.getString("value")); } @@ -88,6 +107,12 @@ public class PropertyFieldTableTest extends TestCase PropertyFieldTable table1 = new PropertyFieldTable(); table1.setChar("value", 'b'); Assert.assertEquals((Character) 'b', table1.getCharacter("value")); + + //Looking up an invalid value returns null + Assert.assertTrue(table1.getCharacter("Rubbish") == null); + + //Try reading value as a string + Assert.assertEquals("b", table1.getString("value")); } public void testDoubleLookup() @@ -95,6 +120,13 @@ public class PropertyFieldTableTest extends TestCase PropertyFieldTable table1 = new PropertyFieldTable(); table1.setDouble("value", Double.MAX_VALUE); Assert.assertEquals(Double.MAX_VALUE, table1.getDouble("value")); + + //Looking up an invalid value returns null + Assert.assertTrue(table1.getDouble("Rubbish") == null); + + //Try reading value as a string + Assert.assertEquals("" + Double.MAX_VALUE, table1.getString("value")); + } public void testFloatLookup() @@ -102,6 +134,13 @@ public class PropertyFieldTableTest extends TestCase PropertyFieldTable table1 = new PropertyFieldTable(); table1.setFloat("value", Float.MAX_VALUE); Assert.assertEquals(Float.MAX_VALUE, table1.getFloat("value")); + + //Looking up an invalid value returns null + Assert.assertTrue(table1.getFloat("Rubbish") == null); + + //Try reading value as a string + Assert.assertEquals("" + Float.MAX_VALUE, table1.getString("value")); + } public void testIntLookup() @@ -109,6 +148,13 @@ public class PropertyFieldTableTest extends TestCase PropertyFieldTable table1 = new PropertyFieldTable(); table1.setInteger("value", Integer.MAX_VALUE); Assert.assertEquals((Integer) Integer.MAX_VALUE, table1.getInteger("value")); + + //Looking up an invalid value returns null + Assert.assertTrue(table1.getInteger("Rubbish") == null); + + //Try reading value as a string + Assert.assertEquals("" + Integer.MAX_VALUE, table1.getString("value")); + } public void testLongLookup() @@ -116,6 +162,13 @@ public class PropertyFieldTableTest extends TestCase PropertyFieldTable table1 = new PropertyFieldTable(); table1.setLong("value", Long.MAX_VALUE); Assert.assertEquals((Long) Long.MAX_VALUE, table1.getLong("value")); + + //Looking up an invalid value returns null + Assert.assertTrue(table1.getLong("Rubbish") == null); + + //Try reading value as a string + Assert.assertEquals("" + Long.MAX_VALUE, table1.getString("value")); + } public void testBytesLookup() @@ -124,6 +177,9 @@ public class PropertyFieldTableTest extends TestCase byte[] bytes = {99, 98, 97, 96, 95}; table1.setBytes("bytes", bytes); assertBytesEqual(bytes, table1.getBytes("bytes")); + + //Looking up an invalid value returns null + Assert.assertTrue(table1.getBytes("Rubbish") == null); } // Failed Lookups @@ -328,6 +384,96 @@ public class PropertyFieldTableTest extends TestCase { FieldTable result = FieldTableFactory.newFieldTable(); int size = 0; + + result.setBoolean("boolean", true); + size += 1 + EncodingUtils.encodedShortStringLength("boolean") + EncodingUtils.encodedBooleanLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + + result.setByte("byte", (byte) Byte.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("byte") + EncodingUtils.encodedByteLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + + byte[] _bytes = {99, 98, 97, 96, 95}; + + result.setBytes("bytes", _bytes); + size += 1 + EncodingUtils.encodedShortStringLength("bytes") + 1 + EncodingUtils.encodedByteLength() * _bytes.length; + Assert.assertEquals(size, result.getEncodedSize()); + + result.setChar("char", (char) 'c'); + size += 1 + EncodingUtils.encodedShortStringLength("char") + EncodingUtils.encodedCharacterLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + result.setDouble("double", (double) Double.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("double") + EncodingUtils.encodedDoubleLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + result.setFloat("float", (float) Float.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("float") + EncodingUtils.encodedFloatLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + result.setInteger("int", (int) Integer.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("int") + EncodingUtils.encodedIntegerLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + + result.setLong("long", (long) Long.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("long") + EncodingUtils.encodedLongLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + result.setShort("short", (short) Short.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("short") + EncodingUtils.encodedShortLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + result.setString("result", "Hello"); + size += 1 + EncodingUtils.encodedShortStringLength("result") + EncodingUtils.encodedLongStringLength("Hello"); + Assert.assertEquals(size, result.getEncodedSize()); + + + result.setObject("object-bool", true); + size += 1 + EncodingUtils.encodedShortStringLength("object-bool") + EncodingUtils.encodedBooleanLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + result.setObject("object-byte", Byte.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("object-byte") + EncodingUtils.encodedByteLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + result.setObject("object-bytes", _bytes); + size += 1 + EncodingUtils.encodedShortStringLength("object-bytes") + 1 + EncodingUtils.encodedByteLength() * _bytes.length; + Assert.assertEquals(size, result.getEncodedSize()); + + result.setObject("object-char", 'c'); + size += 1 + EncodingUtils.encodedShortStringLength("object-char") + EncodingUtils.encodedCharacterLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + result.setObject("object-double", Double.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("object-double") + EncodingUtils.encodedDoubleLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + result.setObject("object-float", Float.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("object-float") + EncodingUtils.encodedFloatLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + result.setObject("object-int", Integer.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("object-int") + EncodingUtils.encodedIntegerLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + + result.setObject("object-long", Long.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("object-long") + EncodingUtils.encodedLongLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + result.setObject("object-short", Short.MAX_VALUE); + size += 1 + EncodingUtils.encodedShortStringLength("object-short") + EncodingUtils.encodedShortLength(); + Assert.assertEquals(size, result.getEncodedSize()); + + } + + public void testEncodingSize1() + { + FieldTable result = FieldTableFactory.newFieldTable(); + int size = 0; result.put("one", 1L); size = EncodingUtils.encodedShortStringLength("one"); size += 1 + EncodingUtils.encodedLongLength(); |
