summaryrefslogtreecommitdiff
path: root/cppe/include/IceE/BasicStream.h
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2006-05-01 18:31:55 +0000
committerDwayne Boone <dwayne@zeroc.com>2006-05-01 18:31:55 +0000
commit75ae8f6e9822d23c83c5e1efec31a82d27a0047b (patch)
tree59e538a9a7e601768574e3179390a73fbb0b933b /cppe/include/IceE/BasicStream.h
parentremoving redundant 'Client' portion from filter property names (diff)
downloadice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.tar.bz2
ice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.tar.xz
ice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.zip
Added ability to configure string converters
Diffstat (limited to 'cppe/include/IceE/BasicStream.h')
-rw-r--r--cppe/include/IceE/BasicStream.h143
1 files changed, 123 insertions, 20 deletions
diff --git a/cppe/include/IceE/BasicStream.h b/cppe/include/IceE/BasicStream.h
index fc968be6833..289f30b2839 100644
--- a/cppe/include/IceE/BasicStream.h
+++ b/cppe/include/IceE/BasicStream.h
@@ -16,6 +16,7 @@
#include <IceE/AutoArray.h>
#include <IceE/Protocol.h>
#include <IceE/Unicode.h>
+#include <IceE/StringConverter.h>
namespace Ice
{
@@ -33,11 +34,55 @@ class ICE_API BasicStream : public Buffer
{
public:
- BasicStream(Instance* instance, int messageSizeMax) :
+ class UTF8BufferI : public Ice::UTF8Buffer
+ {
+ public:
+
+ UTF8BufferI(BasicStream& stream) :
+ _stream(stream)
+ {
+ }
+
+ Ice::Byte*
+ getMoreBytes(size_t howMany, Ice::Byte* firstUnused)
+ {
+ assert(howMany > 0);
+
+ if(firstUnused != 0)
+ {
+ //
+ // Return unused bytes
+ //
+ _stream.b.resize(firstUnused - _stream.b.begin());
+ }
+
+ //
+ // Index of first unused byte
+ //
+ Container::size_type pos = _stream.b.size();
+
+ //
+ // Since resize may reallocate the buffer, when firstUnused != 0, the
+ // return value can be != firstUnused
+ //
+ _stream.resize(pos + howMany);
+
+ return &_stream.b[pos];
+ }
+
+ private:
+
+ BasicStream& _stream;
+ };
+
+ BasicStream(Instance* instance, int messageSizeMax, Ice::StringConverterPtr stringConverter,
+ Ice::WstringConverterPtr wstringConverter) :
_instance(instance),
_currentReadEncaps(0),
_currentWriteEncaps(0),
_messageSizeMax(messageSizeMax),
+ _stringConverter(stringConverter),
+ _wstringConverter(wstringConverter),
_seqDataStack(0)
{
// Inlined for performance reasons.
@@ -254,6 +299,32 @@ public:
}
}
+ void rewriteSize(Ice::Int v, Container::iterator dest)
+ {
+ assert(v >= 0);
+ if(v > 254)
+ {
+ *dest++ = Ice::Byte(255);
+#ifdef ICE_BIG_ENDIAN
+ const Ice::Byte* src = reinterpret_cast<const Ice::Byte*>(&v) + sizeof(Ice::Int) - 1;
+ *dest++ = *src--;
+ *dest++ = *src--;
+ *dest++ = *src--;
+ *dest = *src;
+#else
+ const Ice::Byte* src = reinterpret_cast<const Ice::Byte*>(&v);
+ *dest++ = *src++;
+ *dest++ = *src++;
+ *dest++ = *src++;
+ *dest = *src;
+#endif
+ }
+ else
+ {
+ *dest = static_cast<Ice::Byte>(v);
+ }
+ }
+
void
readSize(Ice::Int& v) // Inlined for performance reasons.
{
@@ -418,16 +489,24 @@ public:
//
void write(const char*);
+ void writeConverted(const std::string& v);
void write(const std::string& v)
{
- Ice::Int sz = static_cast<Ice::Int>(v.size());
- writeSize(sz);
- if(sz > 0)
- {
- Container::size_type pos = b.size();
- resize(pos + sz);
- memcpy(&b[pos], v.c_str(), sz);
- }
+ Ice::Int sz = static_cast<Ice::Int>(v.size());
+ if(sz > 0 && _stringConverter)
+ {
+ writeConverted(v);
+ }
+ else
+ {
+ writeSize(sz);
+ if(sz > 0)
+ {
+ Container::size_type pos = b.size();
+ resize(pos + sz);
+ memcpy(&b[pos], v.data(), sz);
+ }
+ }
}
void write(const std::string*, const std::string*);
void read(std::string& v)
@@ -440,8 +519,15 @@ public:
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
- std::string(reinterpret_cast<const char*>(&*i), reinterpret_cast<const char*>(&*i) + sz).swap(v);
-// v.assign(reinterpret_cast<const char*>(&(*i)), sz);
+ if(_stringConverter)
+ {
+ _stringConverter->fromUTF8(i, i + sz, v);
+ }
+ else
+ {
+ std::string(reinterpret_cast<const char*>(&*i), reinterpret_cast<const char*>(&*i) + sz).swap(v);
+// v.assign(reinterpret_cast<const char*>(&(*i)), sz);
+ }
i += sz;
}
else
@@ -451,16 +537,24 @@ public:
}
void read(std::vector<std::string>&);
+ void writeConverted(const std::wstring& v);
void write(const std::wstring& v)
{
- std::string s = IceUtil::wstringToString(v);
- Ice::Int sz = static_cast<Ice::Int>(s.size());
- writeSize(sz);
- if(sz > 0)
+ if(v.size() > 0 && _wstringConverter)
{
- Container::size_type pos = b.size();
- resize(pos + sz);
- memcpy(&b[pos], s.c_str(), sz);
+ writeConverted(v);
+ }
+ else
+ {
+ std::string s = IceUtil::wstringToString(v);
+ Ice::Int sz = static_cast<Ice::Int>(s.size());
+ writeSize(sz);
+ if(sz > 0)
+ {
+ Container::size_type pos = b.size();
+ resize(pos + sz);
+ memcpy(&b[pos], s.data(), sz);
+ }
}
}
void write(const std::wstring*, const std::wstring*);
@@ -474,8 +568,15 @@ public:
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
- std::string s(reinterpret_cast<const char*>(&*i), reinterpret_cast<const char*>(&*i) + sz);
- IceUtil::stringToWstring(s).swap(v);
+ if(_wstringConverter)
+ {
+ _wstringConverter->fromUTF8(i, i + sz, v);
+ }
+ else
+ {
+ std::string s(reinterpret_cast<const char*>(&*i), reinterpret_cast<const char*>(&*i) + sz);
+ IceUtil::stringToWstring(s).swap(v);
+ }
i += sz;
}
else
@@ -556,6 +657,8 @@ private:
Container::size_type _writeSlice;
const Container::size_type _messageSizeMax;
+ const Ice::StringConverterPtr _stringConverter;
+ const Ice::WstringConverterPtr _wstringConverter;
struct SeqData
{