Menu

#5 Serialization of > 256 Objects - Reference fix

open
nobody
None
5
2011-11-23
2011-11-23
No

During serialization starting with references > 255 the reference numbers will be serialized incorrectly:

Method: CHessianOutput.WriteRef((int intValue)

Old Code:
m_srOutput.WriteByte((byte) PROT_REF_TYPE);
m_srOutput.WriteByte((byte) (intValue << 24));
m_srOutput.WriteByte((byte) (intValue << 16));
m_srOutput.WriteByte((byte) (intValue << 8));
m_srOutput.WriteByte((byte)intValue);

Problem:
The bit-shift goes into the wrong direction, resulting actually in intValue % 256.

Corrected Code:
m_srOutput.WriteByte((byte) PROT_REF_TYPE);
m_srOutput.WriteByte((byte)(intValue >> 24));
m_srOutput.WriteByte((byte)(intValue >> 16));
m_srOutput.WriteByte((byte)(intValue >> 8));
m_srOutput.WriteByte((byte)intValue);

Hope this will help others with serialization-Problems ;)

Cheers, Arndt

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.