diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/float.cpp | 19 | ||||
| -rw-r--r-- | src/float.h | 3 | ||||
| -rw-r--r-- | src/gatsstream.cpp | 20 |
3 files changed, 26 insertions, 16 deletions
diff --git a/src/float.cpp b/src/float.cpp index 139df3e..e85dff8 100644 --- a/src/float.cpp +++ b/src/float.cpp | |||
| @@ -19,21 +19,28 @@ Gats::Float::~Float() | |||
| 19 | 19 | ||
| 20 | void Gats::Float::write( Bu::Stream &rOut ) const | 20 | void Gats::Float::write( Bu::Stream &rOut ) const |
| 21 | { | 21 | { |
| 22 | char buf[50]; | 22 | if( sWriteCache.isEmpty() ) |
| 23 | 23 | { | |
| 24 | int iSize = snprintf( buf, 50, "%la", fVal ); | 24 | char buf[50]; |
| 25 | 25 | ||
| 26 | int iSize = snprintf( buf, 50, "%la", fVal ); | ||
| 27 | sWriteCache.set( buf, iSize ); | ||
| 28 | } | ||
| 26 | rOut.write("f", 1 ); | 29 | rOut.write("f", 1 ); |
| 27 | Gats::Integer::writePackedInt( rOut, iSize ); | 30 | Gats::Integer::writePackedInt( rOut, sWriteCache.getSize() ); |
| 28 | rOut.write( buf, iSize ); | 31 | rOut.write( sWriteCache.getStr(), sWriteCache.getSize() ); |
| 29 | } | 32 | } |
| 30 | 33 | ||
| 34 | #include <bu/sio.h> | ||
| 35 | using namespace Bu; | ||
| 36 | |||
| 31 | void Gats::Float::read( Bu::Stream &rIn, char cType ) | 37 | void Gats::Float::read( Bu::Stream &rIn, char cType ) |
| 32 | { | 38 | { |
| 33 | int iSize; | 39 | int iSize; |
| 34 | Gats::Integer::readPackedInt( rIn, iSize ); | 40 | Gats::Integer::readPackedInt( rIn, iSize ); |
| 35 | char buf[50]; | 41 | char buf[50]; |
| 36 | rIn.read( buf, iSize ); | 42 | buf[rIn.read( buf, iSize )] = '\0'; |
| 43 | sio << "Reading float, iSize = " << iSize << ", str = " << buf << sio.nl; | ||
| 37 | sscanf( buf, "%la", &fVal ); | 44 | sscanf( buf, "%la", &fVal ); |
| 38 | } | 45 | } |
| 39 | 46 | ||
diff --git a/src/float.h b/src/float.h index 27233ae..f7a3ed3 100644 --- a/src/float.h +++ b/src/float.h | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | #include "gats/object.h" | 4 | #include "gats/object.h" |
| 5 | 5 | ||
| 6 | #include <bu/fstring.h> | ||
| 7 | |||
| 6 | namespace Gats | 8 | namespace Gats |
| 7 | { | 9 | { |
| 8 | class Float : public Gats::Object | 10 | class Float : public Gats::Object |
| @@ -20,6 +22,7 @@ namespace Gats | |||
| 20 | 22 | ||
| 21 | private: | 23 | private: |
| 22 | double fVal; | 24 | double fVal; |
| 25 | mutable Bu::FString sWriteCache; | ||
| 23 | }; | 26 | }; |
| 24 | } | 27 | } |
| 25 | 28 | ||
diff --git a/src/gatsstream.cpp b/src/gatsstream.cpp index 3e9b211..71372db 100644 --- a/src/gatsstream.cpp +++ b/src/gatsstream.cpp | |||
| @@ -7,9 +7,9 @@ | |||
| 7 | #include <arpa/inet.h> | 7 | #include <arpa/inet.h> |
| 8 | #endif | 8 | #endif |
| 9 | 9 | ||
| 10 | // #include <bu/sio.h> | 10 | #include <bu/sio.h> |
| 11 | #include <bu/nullstream.h> | 11 | #include <bu/nullstream.h> |
| 12 | // using namespace Bu; | 12 | using namespace Bu; |
| 13 | 13 | ||
| 14 | Gats::GatsStream::GatsStream( Bu::Stream &rStream ) : | 14 | Gats::GatsStream::GatsStream( Bu::Stream &rStream ) : |
| 15 | rStream( rStream ) | 15 | rStream( rStream ) |
| @@ -40,40 +40,40 @@ Gats::Object *Gats::GatsStream::readObject() | |||
| 40 | 40 | ||
| 41 | uint8_t uVer; | 41 | uint8_t uVer; |
| 42 | qbRead.peek( &uVer, 1 ); | 42 | qbRead.peek( &uVer, 1 ); |
| 43 | // sio << "Gats::GatsStream::readObject(): Packet version: " << (int)uVer << sio.nl; | 43 | sio << "Gats::GatsStream::readObject(): Packet version: " << (int)uVer << sio.nl; |
| 44 | 44 | ||
| 45 | int32_t iSize; | 45 | int32_t iSize; |
| 46 | qbRead.peek( &iSize, 4, 1 ); | 46 | qbRead.peek( &iSize, 4, 1 ); |
| 47 | iSize = ntohl( iSize ); | 47 | iSize = ntohl( iSize ); |
| 48 | // sio << "Gats::GatsStream::readObject(): Header read, looking for " << iSize << "b, we have " << qbRead.getSize() << "b." << sio.nl; | 48 | sio << "Gats::GatsStream::readObject(): Header read, looking for " << iSize << "b, we have " << qbRead.getSize() << "b." << sio.nl; |
| 49 | while( qbRead.getSize() < iSize ) | 49 | while( qbRead.getSize() < iSize ) |
| 50 | { | 50 | { |
| 51 | int32_t iRead = iSize - qbRead.getSize(); | 51 | int32_t iRead = iSize - qbRead.getSize(); |
| 52 | if( iRead > 1500 ) | 52 | if( iRead > 1500 ) |
| 53 | iRead = 1500; | 53 | iRead = 1500; |
| 54 | // sio << "Gats::GatsStream::readObject(): Attempting to read " << iRead << "b." << sio.nl; | 54 | sio << "Gats::GatsStream::readObject(): Attempting to read " << iRead << "b." << sio.nl; |
| 55 | int32_t iReal = rStream.read( buf, iRead ); | 55 | int32_t iReal = rStream.read( buf, iRead ); |
| 56 | // sio << "Gats::GatsStream::readObject(): Read " << iReal << "b." << sio.nl; | 56 | sio << "Gats::GatsStream::readObject(): Read " << iReal << "b." << sio.nl; |
| 57 | qbRead.write( buf, iReal ); | 57 | qbRead.write( buf, iReal ); |
| 58 | if( iReal < iRead ) | 58 | if( iReal < iRead ) |
| 59 | { | 59 | { |
| 60 | // sio << "Gats::GatsStream::readObject(): Insufficient data read in block, bailing on read." << sio.nl; | 60 | sio << "Gats::GatsStream::readObject(): Insufficient data read in block, bailing on read." << sio.nl; |
| 61 | return NULL; | 61 | return NULL; |
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | if( qbRead.getSize() < iSize ) | 65 | if( qbRead.getSize() < iSize ) |
| 66 | { | 66 | { |
| 67 | // sio << "Gats::GatsStream::readObject(): Somehow, we still don't have enough data, bailing." << sio.nl; | 67 | sio << "Gats::GatsStream::readObject(): Somehow, we still don't have enough data, bailing." << sio.nl; |
| 68 | return NULL; | 68 | return NULL; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | // sio << "Gats::GatsStream::readObject(): We have " << qbRead.getSize() << "b of " << iSize << "b, time to read the object." << sio.nl; | 71 | sio << "Gats::GatsStream::readObject(): We have " << qbRead.getSize() << "b of " << iSize << "b, time to read the object." << sio.nl; |
| 72 | 72 | ||
| 73 | qbRead.seek( 5 ); | 73 | qbRead.seek( 5 ); |
| 74 | Gats::Object *pObj = Gats::Object::read( qbRead ); | 74 | Gats::Object *pObj = Gats::Object::read( qbRead ); |
| 75 | 75 | ||
| 76 | // sio << "Gats::GatsStream::readObject(): Read completed, there are " << qbRead.getSize() << "b left in the buffer." << sio.nl; | 76 | sio << "Gats::GatsStream::readObject(): Read completed, there are " << qbRead.getSize() << "b left in the buffer." << sio.nl; |
| 77 | return pObj; | 77 | return pObj; |
| 78 | } | 78 | } |
| 79 | 79 | ||
