code_carnage
July 21st, 2008, 07:28 AM
Hello Gurus,
I am facing trouble in serializing and deserializing int.
typedef char int_8;
int_8* SerializeInt(int value)
{
int_8* buff = new int_8[4];
*( buff++ ) = ( int_8 )( value >> 24 );
*( buff++ ) = ( int_8 )( value >> 16 );
*( buff++ ) = ( int_8 )( value >> 8 );
*( buff++ ) = ( int_8 )( value );
return buff;
}
int DeserializeInt(int_8*& m_buff)
{
int temp = *( m_buff++ );
temp = ( temp << 8 | *( m_buff++ ) );
temp = ( temp << 8 | *( m_buff++ ) );
temp = ( temp << 8 | *( m_buff++ ) );
return temp;
}
Problem is when I use SerializeInt( value) function and pass any value to be serialized and when I deserialized the returned value I get -3 always.
I am not able to locate the problem and debugger also is not of great help here..
Thanks in advance
Regards
Prashant.
I am facing trouble in serializing and deserializing int.
typedef char int_8;
int_8* SerializeInt(int value)
{
int_8* buff = new int_8[4];
*( buff++ ) = ( int_8 )( value >> 24 );
*( buff++ ) = ( int_8 )( value >> 16 );
*( buff++ ) = ( int_8 )( value >> 8 );
*( buff++ ) = ( int_8 )( value );
return buff;
}
int DeserializeInt(int_8*& m_buff)
{
int temp = *( m_buff++ );
temp = ( temp << 8 | *( m_buff++ ) );
temp = ( temp << 8 | *( m_buff++ ) );
temp = ( temp << 8 | *( m_buff++ ) );
return temp;
}
Problem is when I use SerializeInt( value) function and pass any value to be serialized and when I deserialized the returned value I get -3 always.
I am not able to locate the problem and debugger also is not of great help here..
Thanks in advance
Regards
Prashant.