You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2006/12/14 02:02:14 UTC
svn commit: r486913 - in
/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq:
io/DataInputStream.cpp io/DataInputStream.h io/DataOutputStream.cpp
io/DataOutputStream.h util/Endian.h
Author: tabish
Date: Wed Dec 13 17:02:13 2006
New Revision: 486913
URL: http://svn.apache.org/viewvc?view=rev&rev=486913
Log:
http://issues.apache.org/activemq/browse/AMQCPP-25
Modified:
incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp
incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.h
incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp
incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.h
incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Endian.h
Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp?view=diff&rev=486913&r1=486912&r2=486913
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp Wed Dec 13 17:02:13 2006
@@ -134,8 +134,18 @@
short DataInputStream::readShort() throw ( io::IOException, io::EOFException ) {
try {
unsigned short value = 0;
+
+ //unsigned char byte1 = this->readByte();
+ //unsigned char byte2 = this->readByte();
+ //
+ //value |= (byte2 << 8 | byte1 << 0);
+
+ //char* temp = (char*)&value;
+ //
+ //return (short)Endian::byteSwap( value );
+
this->readFully( ( unsigned char* )&value, 0, sizeof( unsigned short ) );
- return (short)Endian::byteSwap( value );
+ return Endian::byteSwap( value );
}
AMQ_CATCH_RETHROW( IOException )
AMQ_CATCHALL_THROW( IOException )
@@ -196,6 +206,28 @@
}
AMQ_CATCH_RETHROW( IOException )
AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string DataInputStream::readString()
+ throw ( io::IOException, io::EOFException ) {
+ try {
+ std::string retVal;
+ char temp = 0;
+
+ while( true ){
+ temp = readChar();
+
+ // Append no matter what
+ retVal += temp;
+
+ // if null is found we are done.
+ if( temp == '\0' ) break;
+ }
+ return retVal;
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCHALL_THROW( IOException )
}
////////////////////////////////////////////////////////////////////////////////
Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.h?view=diff&rev=486913&r1=486912&r2=486913
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.h Wed Dec 13 17:02:13 2006
@@ -256,6 +256,14 @@
* @throws IOException
* @throws EOFException
*/
+ virtual std::string readString()
+ throw ( io::IOException, io::EOFException );
+
+ /**
+ *
+ * @throws IOException
+ * @throws EOFException
+ */
virtual std::string readUTF()
throw ( io::IOException, io::EOFException );
Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp?view=diff&rev=486913&r1=486912&r2=486913
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp Wed Dec 13 17:02:13 2006
@@ -46,7 +46,24 @@
}
////////////////////////////////////////////////////////////////////////////////
-void DataOutputStream::write( const unsigned char* buffer, const int len )
+void DataOutputStream::write( const std::vector<unsigned char>& buffer )
+ throw ( IOException ) {
+
+ try {
+
+ if( buffer.size() == 0 ){
+ // nothing to write.
+ return;
+ }
+
+ outputStream->write( &buffer[0], buffer.size() );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::write( const unsigned char* buffer, int len )
throw ( IOException ) {
try {
@@ -57,6 +74,17 @@
}
////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::write( const unsigned char* buffer, int offset, int len )
+ throw ( IOException ) {
+
+ try {
+ outputStream->write( buffer+offset, len );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
void DataOutputStream::writeBoolean( bool value ) throw ( IOException ) {
try {
unsigned char ivalue = 0;
@@ -80,8 +108,13 @@
////////////////////////////////////////////////////////////////////////////////
void DataOutputStream::writeShort( short value ) throw ( IOException ) {
+ writeUnsignedShort( (unsigned short)value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeUnsignedShort( unsigned short value ) throw ( IOException ) {
try {
- value = Endian::byteSwap( ( unsigned short )value );
+ value = Endian::byteSwap( value );
write( ( unsigned char* )&value, sizeof( value ) );
}
AMQ_CATCH_RETHROW( IOException )
Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.h?view=diff&rev=486913&r1=486912&r2=486913
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.h Wed Dec 13 17:02:13 2006
@@ -63,7 +63,7 @@
* @param c the byte.
* @throws IOException thrown if an error occurs.
*/
- virtual void write( const unsigned char c ) throw ( IOException );
+ virtual void write( unsigned char c ) throw ( IOException );
/**
* Writes an array of bytes to the output stream. the counter
@@ -72,7 +72,25 @@
* @param len The number of bytes from the buffer to be written.
* @throws IOException thrown if an error occurs.
*/
- virtual void write( const unsigned char* buffer, const int len )
+ virtual void write( const unsigned char* buffer, int len )
+ throw ( IOException );
+
+ /**
+ * Writes an array of bytes to the output stream. the counter
+ * written is incremented by len.
+ * @param buffer The array of bytes to write.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer, int offset, int len )
+ throw ( IOException );
+
+ /**
+ * Writes an array of bytes to the output stream.
+ * @param buffer The bytes to write.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const std::vector<unsigned char>& buffer )
throw ( IOException );
/**
@@ -103,6 +121,13 @@
* @throws IOException
*/
virtual void writeShort( short value ) throw ( IOException );
+
+ /**
+ * Writes a unsigned short to the bytes message stream as a 2 byte value
+ * @param value - unsigned short to write to the stream
+ * @throws IOException
+ */
+ virtual void writeUnsignedShort( unsigned short value ) throw ( IOException );
/**
* Writes out a char to the underlying output stream as a one byte
Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Endian.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Endian.h?view=diff&rev=486913&r1=486912&r2=486913
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Endian.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Endian.h Wed Dec 13 17:02:13 2006
@@ -104,47 +104,6 @@
namespace activemq{
namespace util{
-/*#ifdef IFR_IS_BIGENDIAN
-inline unsigned int htoni (unsigned int i) { return i; }
-inline unsigned long long htonll (unsigned long long ll) { return ll; }
-inline float htonf (float f) { return f; }
-inline double htond (double d) { return d; }
-inline unsigned int ntohi (unsigned int i) { return i; }
-inline unsigned long long ntohll (unsigned long long ll) { return ll; }
-inline float ntohf (float f) { return f; }
-inline double ntohd (double d) { return d; }
-#else // !IFR_IS_BIGENDIAN
-
-inline unsigned int htoni (unsigned int i) {
- return ( i << 8 ) & 0xFF00 |
- ( i >> 8 ) & 0x00FF;
-}
-inline unsigned long long htonll (unsigned long long ll) {
- return
- ( ll << 56 ) & 0xFF00000000000000ULL |
- ( ll << 40 ) & 0x00FF000000000000ULL |
- ( ll << 24 ) & 0x0000FF0000000000ULL |
- ( ll << 8 ) & 0x000000FF00000000ULL |
- ( ll >> 8 ) & 0x00000000FF000000ULL |
- ( ll >> 24 ) & 0x0000000000FF0000ULL |
- ( ll >> 40 ) & 0x000000000000FF00ULL |
- ( ll >> 56 ) & 0x00000000000000FFULL;
-}
-
-
-inline float htonf (float f) {
- unsigned int i = htonl( *(unsigned int *)&f ) ;
- return *(float *)&i ;
-}
-inline double htond (double d) {
- unsigned long long ll = htonll( *(unsigned long long *)&d ) ;
- return *(double *)&ll ;
-}
-inline unsigned int ntohi (unsigned int i) { return htoni (i); }
-inline unsigned long long ntohll (unsigned long long ll) { return htonll (ll); }
-inline float ntohf (float f) { return htonf (f); }
-inline double ntohd (double d) { return htond (d); }
-*/
class Endian{
public:
@@ -162,38 +121,71 @@
}
static uint8_t byteSwap( uint8_t value ){
- byteSwap( (unsigned char*)&value, sizeof( value ) );
- return value;
+
+ #ifdef IFR_IS_BIGENDIAN
+ return value;
+ #endif
+
+ return value;
}
static uint16_t byteSwap( uint16_t value ){
- byteSwap( (unsigned char*)&value, sizeof( value ) );
- return value;
+
+ #ifdef IFR_IS_BIGENDIAN
+ return value;
+ #endif
+
+ return (((unsigned short)value & 0xFF00 ) >> 8 ) |
+ (((unsigned short)value & 0x00FF ) << 8 );
}
static uint32_t byteSwap( uint32_t value ){
- byteSwap( (unsigned char*)&value, sizeof( value ) );
- return value;
+
+ #ifdef IFR_IS_BIGENDIAN
+ return value;
+ #endif
+
+ return (((unsigned int)value & 0xFF000000 ) >> 24 ) |
+ (((unsigned int)value & 0x00FF0000 ) >> 8 ) |
+ (((unsigned int)value & 0x0000FF00 ) << 8 ) |
+ (((unsigned int)value & 0x000000FF ) << 24 );
}
static uint64_t byteSwap( uint64_t value ){
- byteSwap( (unsigned char*)&value, sizeof( value ) );
- return value;
+
+ #ifdef IFR_IS_BIGENDIAN
+ return value;
+ #endif
+
+ return (((unsigned long long)value & 0xFF00000000000000ULL ) >> 56 ) |
+ (((unsigned long long)value & 0x00FF000000000000ULL ) >> 40 ) |
+ (((unsigned long long)value & 0x0000FF0000000000ULL ) >> 24 ) |
+ (((unsigned long long)value & 0x000000FF00000000ULL ) >> 8 ) |
+ (((unsigned long long)value & 0x00000000FF000000ULL ) << 8 ) |
+ (((unsigned long long)value & 0x0000000000FF0000ULL ) << 24 ) |
+ (((unsigned long long)value & 0x000000000000FF00ULL ) << 40 ) |
+ (((unsigned long long)value & 0x00000000000000FFULL ) << 56 );
}
static float byteSwap( float value ){
- byteSwap( (unsigned char*)&value, sizeof( value ) );
- return value;
+
+ #ifdef IFR_IS_BIGENDIAN
+ return value;
+ #endif
+
+ return (float)( byteSwap( (unsigned int)value ) );
}
static double byteSwap( double value ){
- byteSwap( (unsigned char*)&value, sizeof( value ) );
- return value;
+
+ #ifdef IFR_IS_BIGENDIAN
+ return value;
+ #endif
+
+ return (double)( byteSwap( (unsigned long long)value ) );
}
};
-//#endif // IFR_IS_BIGENDIAN
-
}}
#endif /*ACTIVEMQ_UTIL_ENDIAN_H*/