summaryrefslogtreecommitdiff
path: root/cppe/src
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/src
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/src')
-rw-r--r--cppe/src/IceE/BasicStream.cpp116
-rwxr-xr-xcppe/src/IceE/Connection.cpp23
-rw-r--r--cppe/src/IceE/Incoming.cpp3
-rw-r--r--cppe/src/IceE/Outgoing.cpp4
4 files changed, 137 insertions, 9 deletions
diff --git a/cppe/src/IceE/BasicStream.cpp b/cppe/src/IceE/BasicStream.cpp
index e39fa2053a2..611f9bc9b78 100644
--- a/cppe/src/IceE/BasicStream.cpp
+++ b/cppe/src/IceE/BasicStream.cpp
@@ -1291,6 +1291,64 @@ IceInternal::BasicStream::write(const char*)
*/
void
+IceInternal::BasicStream::writeConverted(const string& v)
+{
+ //
+ // What is the size of the resulting UTF-8 encoded string?
+ // Impossible to tell, so we guess. If we don't guess correctly,
+ // we'll have to fix the mistake afterwards
+ //
+
+ Int guessedSize = static_cast<Int>(v.size());
+ writeSize(guessedSize); // writeSize() only writes the size; it does not reserve any buffer space.
+
+ size_t firstIndex = b.size();
+ UTF8BufferI buffer(*this);
+
+ Byte* lastByte = _stringConverter->toUTF8(v.data(), v.data() + v.size(), buffer);
+ if(lastByte != b.end())
+ {
+ b.resize(lastByte - b.begin());
+ }
+ size_t lastIndex = b.size();
+
+ Int actualSize = static_cast<Int>(lastIndex - firstIndex);
+
+ //
+ // Check against the guess
+ //
+ if(guessedSize != actualSize)
+ {
+ if(guessedSize <= 254 && actualSize > 254)
+ {
+ //
+ // Move the UTF-8 sequence 4 bytes further
+ // Use memmove instead of memcpy since the source and destination typically overlap.
+ //
+ resize(b.size() + 4);
+ std::memmove(b.begin() + firstIndex + 4, b.begin() + firstIndex, actualSize);
+ }
+ else if(guessedSize > 254 && actualSize <= 254)
+ {
+ //
+ // Move the UTF-8 sequence 4 bytes back
+ //
+ std::memmove(b.begin() + firstIndex - 4, b.begin() + firstIndex, actualSize);
+ resize(b.size() - 4);
+ }
+
+ if(guessedSize <= 254)
+ {
+ rewriteSize(actualSize, b.begin() + firstIndex - 1);
+ }
+ else
+ {
+ rewriteSize(actualSize, b.begin() + firstIndex - 1 - 4);
+ }
+ }
+}
+
+void
IceInternal::BasicStream::write(const string* begin, const string* end)
{
Int sz = static_cast<Int>(end - begin);
@@ -1328,6 +1386,64 @@ IceInternal::BasicStream::read(vector<string>& v)
}
void
+IceInternal::BasicStream::writeConverted(const wstring& v)
+{
+ //
+ // What is the size of the resulting UTF-8 encoded string?
+ // Impossible to tell, so we guess. If we don't guess correctly,
+ // we'll have to fix the mistake afterwards
+ //
+
+ Int guessedSize = static_cast<Int>(v.size());
+ writeSize(guessedSize); // writeSize() only writes the size; it does not reserve any buffer space.
+
+ size_t firstIndex = b.size();
+ UTF8BufferI buffer(*this);
+
+ Byte* lastByte = _wstringConverter->toUTF8(v.data(), v.data() + v.size(), buffer);
+ if(lastByte != b.end())
+ {
+ b.resize(lastByte - b.begin());
+ }
+ size_t lastIndex = b.size();
+
+ Int actualSize = static_cast<Int>(lastIndex - firstIndex);
+
+ //
+ // Check against the guess
+ //
+ if(guessedSize != actualSize)
+ {
+ if(guessedSize <= 254 && actualSize > 254)
+ {
+ //
+ // Move the UTF-8 sequence 4 bytes further
+ // Use memmove instead of memcpy since the source and destination typically overlap.
+ //
+ resize(b.size() + 4);
+ std::memmove(b.begin() + firstIndex + 4, b.begin() + firstIndex, actualSize);
+ }
+ else if(guessedSize > 254 && actualSize <= 254)
+ {
+ //
+ // Move the UTF-8 sequence 4 bytes back
+ //
+ std::memmove(b.begin() + firstIndex - 4, b.begin() + firstIndex, actualSize);
+ resize(b.size() - 4);
+ }
+
+ if(guessedSize <= 254)
+ {
+ rewriteSize(actualSize, b.begin() + firstIndex - 1);
+ }
+ else
+ {
+ rewriteSize(actualSize, b.begin() + firstIndex - 1 - 4);
+ }
+ }
+}
+
+void
IceInternal::BasicStream::write(const wstring* begin, const wstring* end)
{
Int sz = static_cast<Int>(end - begin);
diff --git a/cppe/src/IceE/Connection.cpp b/cppe/src/IceE/Connection.cpp
index 9b76b84b31a..08b13996902 100755
--- a/cppe/src/IceE/Connection.cpp
+++ b/cppe/src/IceE/Connection.cpp
@@ -578,7 +578,8 @@ Ice::Connection::abortBatchRequest()
// safe old requests in the batch stream, as they might be
// corrupted due to incomplete marshaling.
//
- BasicStream dummy(_instance.get(), _instance->messageSizeMax());
+ BasicStream dummy(_instance.get(), _instance->messageSizeMax(), _instance->initializationData().stringConverter,
+ _instance->initializationData().wstringConverter);
_batchStream.swap(dummy);
_batchRequestNum = 0;
@@ -697,7 +698,8 @@ Ice::Connection::flushBatchRequests()
//
// Reset the batch stream, and notify that flushing is over.
//
- BasicStream dummy(_instance.get(), _instance->messageSizeMax());
+ BasicStream dummy(_instance.get(), _instance->messageSizeMax(), _instance->initializationData().stringConverter,
+ _instance->initializationData().wstringConverter);
_batchStream.swap(dummy);
_batchRequestNum = 0;
_batchStreamInUse = false;
@@ -912,10 +914,12 @@ Ice::Connection::Connection(const InstancePtr& instance,
_in(_instance.get(), this, _stream, adapter),
#endif
#ifndef ICEE_PURE_BLOCKING_CLIENT
- _stream(_instance.get(), _instance->messageSizeMax()),
+ _stream(_instance.get(), _instance->messageSizeMax(), _instance->initializationData().stringConverter,
+ _instance->initializationData().wstringConverter),
#endif
#ifdef ICEE_HAS_BATCH
- _batchStream(_instance.get(), _instance->messageSizeMax()),
+ _batchStream(_instance.get(), _instance->messageSizeMax(), _instance->initializationData().stringConverter,
+ _instance->initializationData().wstringConverter),
_batchStreamInUse(false),
_batchRequestNum(0),
#endif
@@ -1054,7 +1058,9 @@ Ice::Connection::validate()
#ifndef ICEE_PURE_CLIENT
if(active)
{
- BasicStream os(_instance.get(), _instance->messageSizeMax());
+ BasicStream os(_instance.get(), _instance->messageSizeMax(),
+ _instance->initializationData().stringConverter,
+ _instance->initializationData().wstringConverter);
os.write(magic[0]);
os.write(magic[1]);
os.write(magic[2]);
@@ -1083,7 +1089,9 @@ Ice::Connection::validate()
else
#endif
{
- BasicStream is(_instance.get(), _instance->messageSizeMax());
+ BasicStream is(_instance.get(), _instance->messageSizeMax(),
+ _instance->initializationData().stringConverter,
+ _instance->initializationData().wstringConverter);
is.b.resize(headerSize);
is.i = is.b.begin();
try
@@ -1353,7 +1361,8 @@ Ice::Connection::initiateShutdown() const
//
// Before we shut down, we send a close connection message.
//
- BasicStream os(_instance.get(), _instance->messageSizeMax());
+ BasicStream os(_instance.get(), _instance->messageSizeMax(), _instance->initializationData().stringConverter,
+ _instance->initializationData().wstringConverter);
os.write(magic[0]);
os.write(magic[1]);
os.write(magic[2]);
diff --git a/cppe/src/IceE/Incoming.cpp b/cppe/src/IceE/Incoming.cpp
index f9de4efb110..b986dbf3a2e 100644
--- a/cppe/src/IceE/Incoming.cpp
+++ b/cppe/src/IceE/Incoming.cpp
@@ -25,7 +25,8 @@ using namespace Ice;
using namespace IceInternal;
IceInternal::Incoming::Incoming(Instance* inst, Connection* con, BasicStream& is, const ObjectAdapterPtr& adapter) :
- _os(inst, inst->messageSizeMax()),
+ _os(inst, inst->messageSizeMax(), inst->initializationData().stringConverter,
+ inst->initializationData().wstringConverter),
_is(is),
_connection(con)
{
diff --git a/cppe/src/IceE/Outgoing.cpp b/cppe/src/IceE/Outgoing.cpp
index 0da4ad89209..6e1d64206b6 100644
--- a/cppe/src/IceE/Outgoing.cpp
+++ b/cppe/src/IceE/Outgoing.cpp
@@ -49,7 +49,9 @@ IceInternal::Outgoing::Outgoing(Connection* connection, Reference* ref, const st
_connection(connection),
_reference(ref),
_state(StateUnsent),
- _stream(ref->getInstance().get(), ref->getInstance()->messageSizeMax())
+ _stream(ref->getInstance().get(), ref->getInstance()->messageSizeMax(),
+ ref->getInstance()->initializationData().stringConverter,
+ ref->getInstance()->initializationData().wstringConverter)
{
switch(_reference->getMode())
{