|
|
|
[
Permlink
| « Hide
]
James Strachan - 22/May/06 11:29 AM
added versions
Good find.. I think it's worth delaying the 4.0 release to fix this.
oh. I think I may read this too quickly.
I just reviewed the code, and the size field is consistent in usage in both the loose and tight encoding. They size written is the number of bytes that will follow. As I see it both loose and tight encoding prefix the size of the playload.
So the total size of a command when it is encoding to bytes would be 4+1+size-of-payload which corresponds to the size-of-payload, type, and payload. This is true for both loose and tight encoding. If I'm wrong please let me know. FWIW, my understanding is that size-of-payload includes the type byte, but not the size bytes. Correct? (see int size=1 on OpenWireFormat.java:223).
I think it may be right in one instance and wrong in another. Using this code as an example, from OpenWireFormat.java:242: DataOutputStream looseOut = dataOut; if( !sizePrefixDisabled ) { baos = new ByteArrayOutputStream(); looseOut = new DataOutputStream(baos); } looseOut.writeByte(type); if( !sizePrefixDisabled ) { looseOut.close(); ByteSequence sequence = baos.toByteSequence(); dataOut.writeInt(sequence.getLength()-4); dataOut.write(sequence.getData(), sequence.getOffset(), sequence.getLength()); } Nowhere was the size written into "baos" yet 4 is being subtracted from its size to put the size on the wire. In another location in the file (the other overload of marshal() : ByteArrayOutputStream baos = new ByteArrayOutputStream(); if( !sizePrefixDisabled ) {
size = sequence.getLength()-4;
ByteArrayPacket packet = new ByteArrayPacket(sequence);
PacketData.writeIntBig(packet, size);
} In this case I think this code is right, since the size has been written in to that sequence. I'll revert the second case I mentioned and run my tests again. OK, I've verified that my code still works with just the first case I mentioned (in the marshal(Object, DataOutputStream) overload) patched. The other case I believe is fine how it is.
Hi Adrew.. this stuf is not easy grok.. glad your keeping us honest.
Your right, I stand corrected, the size field holds the size of the type+playload fields. For a sec there I was thinking it only held the size of the payload. I now agree with your anyalisys that the original patch to line 253 is valid. And also found that the sizePrefixDisabled option was not being honorred in the tight encoding case for that method. This is the new patch what I will be applying shortly. Index: /Users/chirino/sandbox/activemq-4-branch/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
|
|||||||||||||||||||||||||||||||||||||||||||||||