diff options
Diffstat (limited to 'cppe/include/IceE/BasicStream.h')
-rw-r--r-- | cppe/include/IceE/BasicStream.h | 518 |
1 files changed, 259 insertions, 259 deletions
diff --git a/cppe/include/IceE/BasicStream.h b/cppe/include/IceE/BasicStream.h index 2bc6cc488c1..a39c96aedf1 100644 --- a/cppe/include/IceE/BasicStream.h +++ b/cppe/include/IceE/BasicStream.h @@ -87,31 +87,31 @@ public: const Ice::StringConverterPtr& stringConverter, const Ice::WstringConverterPtr& wstringConverter, #endif bool unlimited = false) : - Buffer(messageSizeMax), - _instance(instance), - _currentReadEncaps(0), - _currentWriteEncaps(0), - _messageSizeMax(messageSizeMax), + Buffer(messageSizeMax), + _instance(instance), + _currentReadEncaps(0), + _currentWriteEncaps(0), + _messageSizeMax(messageSizeMax), _unlimited(unlimited), #ifdef ICEE_HAS_WSTRING _stringConverter(stringConverter), _wstringConverter(wstringConverter), #endif - _seqDataStack(0) + _seqDataStack(0) { - // Inlined for performance reasons. + // Inlined for performance reasons. } ~BasicStream() { - // Inlined for performance reasons. - - if(_currentReadEncaps != &_preAllocatedReadEncaps || - _currentWriteEncaps != &_preAllocatedWriteEncaps || - _seqDataStack) - { - clear(); // Not inlined. - } + // Inlined for performance reasons. + + if(_currentReadEncaps != &_preAllocatedReadEncaps || + _currentWriteEncaps != &_preAllocatedWriteEncaps || + _seqDataStack) + { + clear(); // Not inlined. + } } ICE_API void clear(); @@ -126,168 +126,168 @@ public: void resize(Container::size_type sz) { - if(!_unlimited && sz > _messageSizeMax) - { - Ice::throwMemoryLimitException(__FILE__, __LINE__); - } - - b.resize(sz); + if(!_unlimited && sz > _messageSizeMax) + { + Ice::throwMemoryLimitException(__FILE__, __LINE__); + } + + b.resize(sz); } void reset() // Inlined for performance reasons. { b.reset(); - i = b.begin(); + i = b.begin(); } ICE_API void startSeq(int, int); void checkSeq() { - checkSeq(static_cast<int>(b.end() - i)); + checkSeq(static_cast<int>(b.end() - i)); } void checkSeq(int bytesLeft) { - // - // Check, given the number of elements requested for this sequence, - // that this sequence, plus the sum of the sizes of the remaining - // number of elements of all enclosing sequences, would still fit - // within the message. - // - int size = 0; - SeqData* sd = _seqDataStack; - do - { - size += (sd->numElements - 1) * sd->minSize; - sd = sd->previous; - } - while(sd); - - if(size > bytesLeft) - { - Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); - } + // + // Check, given the number of elements requested for this sequence, + // that this sequence, plus the sum of the sizes of the remaining + // number of elements of all enclosing sequences, would still fit + // within the message. + // + int size = 0; + SeqData* sd = _seqDataStack; + do + { + size += (sd->numElements - 1) * sd->minSize; + sd = sd->previous; + } + while(sd); + + if(size > bytesLeft) + { + Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); + } } ICE_API void checkFixedSeq(int, int); // For sequences of fixed-size types. void endElement() { - assert(_seqDataStack); - --_seqDataStack->numElements; + assert(_seqDataStack); + --_seqDataStack->numElements; } ICE_API void endSeq(int); void startWriteEncaps() { - WriteEncaps* oldEncaps = _currentWriteEncaps; - if(!oldEncaps) // First allocated encaps? - { - _currentWriteEncaps = &_preAllocatedWriteEncaps; - } - else - { - _currentWriteEncaps = new WriteEncaps(); - _currentWriteEncaps->previous = oldEncaps; - } - _currentWriteEncaps->start = b.size(); - - write(Ice::Int(0)); // Placeholder for the encapsulation length. - write(encodingMajor); - write(encodingMinor); + WriteEncaps* oldEncaps = _currentWriteEncaps; + if(!oldEncaps) // First allocated encaps? + { + _currentWriteEncaps = &_preAllocatedWriteEncaps; + } + else + { + _currentWriteEncaps = new WriteEncaps(); + _currentWriteEncaps->previous = oldEncaps; + } + _currentWriteEncaps->start = b.size(); + + write(Ice::Int(0)); // Placeholder for the encapsulation length. + write(encodingMajor); + write(encodingMinor); } void endWriteEncaps() { - assert(_currentWriteEncaps); - Container::size_type start = _currentWriteEncaps->start; - Ice::Int sz = static_cast<Ice::Int>(b.size() - start); // Size includes size and version. - Ice::Byte* dest = &(*(b.begin() + start)); + assert(_currentWriteEncaps); + Container::size_type start = _currentWriteEncaps->start; + Ice::Int sz = static_cast<Ice::Int>(b.size() - start); // Size includes size and version. + Ice::Byte* dest = &(*(b.begin() + start)); #ifdef ICE_BIG_ENDIAN - const Ice::Byte* src = reinterpret_cast<const Ice::Byte*>(&sz) + sizeof(Ice::Int) - 1; - *dest++ = *src--; - *dest++ = *src--; - *dest++ = *src--; - *dest = *src; + const Ice::Byte* src = reinterpret_cast<const Ice::Byte*>(&sz) + sizeof(Ice::Int) - 1; + *dest++ = *src--; + *dest++ = *src--; + *dest++ = *src--; + *dest = *src; #else - const Ice::Byte* src = reinterpret_cast<const Ice::Byte*>(&sz); - *dest++ = *src++; - *dest++ = *src++; - *dest++ = *src++; - *dest = *src; + const Ice::Byte* src = reinterpret_cast<const Ice::Byte*>(&sz); + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + *dest = *src; #endif - WriteEncaps* oldEncaps = _currentWriteEncaps; - _currentWriteEncaps = _currentWriteEncaps->previous; - if(oldEncaps == &_preAllocatedWriteEncaps) - { - oldEncaps->reset(); - } - else - { - delete oldEncaps; - } + WriteEncaps* oldEncaps = _currentWriteEncaps; + _currentWriteEncaps = _currentWriteEncaps->previous; + if(oldEncaps == &_preAllocatedWriteEncaps) + { + oldEncaps->reset(); + } + else + { + delete oldEncaps; + } } void startReadEncaps() { - ReadEncaps* oldEncaps = _currentReadEncaps; - if(!oldEncaps) // First allocated encaps? - { - _currentReadEncaps = &_preAllocatedReadEncaps; - } - else - { - _currentReadEncaps = new ReadEncaps(); - _currentReadEncaps->previous = oldEncaps; - } - _currentReadEncaps->start = i - b.begin(); - - // - // I don't use readSize() and writeSize() for encapsulations, - // because when creating an encapsulation, I must know in advance - // how many bytes the size information will require in the data - // stream. If I use an Int, it is always 4 bytes. For - // readSize()/writeSize(), it could be 1 or 5 bytes. - // - Ice::Int sz; - read(sz); - if(sz < 0) - { - Ice::throwNegativeSizeException(__FILE__, __LINE__); - } - if(i - sizeof(Ice::Int) + sz > b.end()) - { - Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); - } - _currentReadEncaps->sz = sz; - - Ice::Byte eMajor; - Ice::Byte eMinor; - read(eMajor); - read(eMinor); - if(eMajor != encodingMajor - || static_cast<unsigned char>(eMinor) > static_cast<unsigned char>(encodingMinor)) - { - Ice::throwUnsupportedEncodingException(__FILE__, __LINE__, eMajor, eMinor, encodingMajor, encodingMinor); - } - _currentReadEncaps->encodingMajor = eMajor; - _currentReadEncaps->encodingMinor = eMinor; + ReadEncaps* oldEncaps = _currentReadEncaps; + if(!oldEncaps) // First allocated encaps? + { + _currentReadEncaps = &_preAllocatedReadEncaps; + } + else + { + _currentReadEncaps = new ReadEncaps(); + _currentReadEncaps->previous = oldEncaps; + } + _currentReadEncaps->start = i - b.begin(); + + // + // I don't use readSize() and writeSize() for encapsulations, + // because when creating an encapsulation, I must know in advance + // how many bytes the size information will require in the data + // stream. If I use an Int, it is always 4 bytes. For + // readSize()/writeSize(), it could be 1 or 5 bytes. + // + Ice::Int sz; + read(sz); + if(sz < 0) + { + Ice::throwNegativeSizeException(__FILE__, __LINE__); + } + if(i - sizeof(Ice::Int) + sz > b.end()) + { + Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); + } + _currentReadEncaps->sz = sz; + + Ice::Byte eMajor; + Ice::Byte eMinor; + read(eMajor); + read(eMinor); + if(eMajor != encodingMajor + || static_cast<unsigned char>(eMinor) > static_cast<unsigned char>(encodingMinor)) + { + Ice::throwUnsupportedEncodingException(__FILE__, __LINE__, eMajor, eMinor, encodingMajor, encodingMinor); + } + _currentReadEncaps->encodingMajor = eMajor; + _currentReadEncaps->encodingMinor = eMinor; } void endReadEncaps() { - assert(_currentReadEncaps); - Container::size_type start = _currentReadEncaps->start; - Ice::Int sz = _currentReadEncaps->sz; - i = b.begin() + start + sz; - - ReadEncaps* oldEncaps = _currentReadEncaps; - _currentReadEncaps = _currentReadEncaps->previous; - if(oldEncaps == &_preAllocatedReadEncaps) - { - oldEncaps->reset(); - } - else - { - delete oldEncaps; - } + assert(_currentReadEncaps); + Container::size_type start = _currentReadEncaps->start; + Ice::Int sz = _currentReadEncaps->sz; + i = b.begin() + start + sz; + + ReadEncaps* oldEncaps = _currentReadEncaps; + _currentReadEncaps = _currentReadEncaps->previous; + if(oldEncaps == &_preAllocatedReadEncaps) + { + oldEncaps->reset(); + } + else + { + delete oldEncaps; + } } ICE_API Ice::Int getReadEncapsSize(); ICE_API void skipEncaps(); @@ -301,16 +301,16 @@ public: void writeSize(Ice::Int v) // Inlined for performance reasons. { - assert(v >= 0); - if(v > 254) - { - write(Ice::Byte(255)); - write(v); - } - else - { - write(static_cast<Ice::Byte>(v)); - } + assert(v >= 0); + if(v > 254) + { + write(Ice::Byte(255)); + write(v); + } + else + { + write(static_cast<Ice::Byte>(v)); + } } void rewriteSize(Ice::Int v, Container::iterator dest) @@ -342,21 +342,21 @@ public: void readSize(Ice::Int& v) // Inlined for performance reasons. { - Ice::Byte byte; - read(byte); - unsigned val = static_cast<unsigned char>(byte); - if(val == 255) - { - read(v); - if(v < 0) - { - Ice::throwNegativeSizeException(__FILE__, __LINE__); - } - } - else - { - v = static_cast<Ice::Int>(static_cast<unsigned char>(byte)); - } + Ice::Byte byte; + read(byte); + unsigned val = static_cast<unsigned char>(byte); + if(val == 255) + { + read(v); + if(v < 0) + { + Ice::throwNegativeSizeException(__FILE__, __LINE__); + } + } + else + { + v = static_cast<Ice::Int>(static_cast<unsigned char>(byte)); + } } ICE_API void writeBlob(const std::vector<Ice::Byte>&); @@ -364,42 +364,42 @@ public: void writeBlob(const Ice::Byte* v, Container::size_type sz) { - if(sz > 0) - { - Container::size_type pos = b.size(); - resize(pos + sz); - memcpy(&b[pos], &v[0], sz); - } + if(sz > 0) + { + Container::size_type pos = b.size(); + resize(pos + sz); + memcpy(&b[pos], &v[0], sz); + } } void readBlob(const Ice::Byte*& v, Container::size_type sz) { - if(sz > 0) - { - v = i; - if(static_cast<Container::size_type>(b.end() - i) < sz) - { - Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); - } - i += sz; - } - else - { - v = i; - } + if(sz > 0) + { + v = i; + if(static_cast<Container::size_type>(b.end() - i) < sz) + { + Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); + } + i += sz; + } + else + { + v = i; + } } void write(Ice::Byte v) // Inlined for performance reasons. { - b.push_back(v); + b.push_back(v); } void read(Ice::Byte& v) // Inlined for performance reasons. { - if(i >= b.end()) - { - Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); - } - v = *i++; + if(i >= b.end()) + { + Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); + } + v = *i++; } ICE_API void write(const Ice::Byte*, const Ice::Byte*); @@ -407,17 +407,17 @@ public: void write(bool v) // Inlined for performance reasons. { - b.push_back(static_cast<Ice::Byte>(v)); + b.push_back(static_cast<Ice::Byte>(v)); } ICE_API void write(const std::vector<bool>&); ICE_API void write(const bool*, const bool*); void read(bool& v) // Inlined for performance reasons. { - if(i >= b.end()) - { - Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); - } - v = *i++; + if(i >= b.end()) + { + Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); + } + v = *i++; } ICE_API void read(std::vector<bool>&); ICE_API bool* read(std::pair<const bool*, const bool*>&); @@ -431,44 +431,44 @@ public: void write(Ice::Int v) // Inlined for performance reasons. { - Container::size_type pos = b.size(); - resize(pos + sizeof(Ice::Int)); - Ice::Byte* dest = &b[pos]; + Container::size_type pos = b.size(); + resize(pos + sizeof(Ice::Int)); + Ice::Byte* dest = &b[pos]; #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; + 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; + const Ice::Byte* src = reinterpret_cast<const Ice::Byte*>(&v); + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + *dest = *src; #endif } void read(Ice::Int& v) // Inlined for performance reasons. { - if(b.end() - i < static_cast<int>(sizeof(Ice::Int))) - { - Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); - } - const Ice::Byte* src = &(*i); - i += sizeof(Ice::Int); + if(b.end() - i < static_cast<int>(sizeof(Ice::Int))) + { + Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); + } + const Ice::Byte* src = &(*i); + i += sizeof(Ice::Int); #ifdef ICE_BIG_ENDIAN - Ice::Byte* dest = reinterpret_cast<Ice::Byte*>(&v) + sizeof(Ice::Int) - 1; - *dest-- = *src++; - *dest-- = *src++; - *dest-- = *src++; - *dest = *src; + Ice::Byte* dest = reinterpret_cast<Ice::Byte*>(&v) + sizeof(Ice::Int) - 1; + *dest-- = *src++; + *dest-- = *src++; + *dest-- = *src++; + *dest = *src; #else - Ice::Byte* dest = reinterpret_cast<Ice::Byte*>(&v); - *dest++ = *src++; - *dest++ = *src++; - *dest++ = *src++; - *dest = *src; + Ice::Byte* dest = reinterpret_cast<Ice::Byte*>(&v); + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + *dest = *src; #endif } @@ -529,14 +529,14 @@ public: ICE_API void write(const std::string*, const std::string*, bool = true); void read(std::string& v, bool convert = true) { - Ice::Int sz; - readSize(sz); - if(sz > 0) - { - if(b.end() - i < sz) - { - Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); - } + Ice::Int sz; + readSize(sz); + if(sz > 0) + { + if(b.end() - i < sz) + { + Ice::throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); + } #ifdef ICEE_HAS_WSTRING if(convert && _stringConverter != 0) { @@ -548,12 +548,12 @@ public: 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 - { - v.clear(); - } + i += sz; + } + else + { + v.clear(); + } } ICE_API void read(std::vector<std::string>&, bool = true); @@ -600,36 +600,36 @@ private: { public: - ReadEncaps() : previous(0) { } // Inlined for performance reasons. - ~ReadEncaps() { } // Inlined for performance reasons. + ReadEncaps() : previous(0) { } // Inlined for performance reasons. + ~ReadEncaps() { } // Inlined for performance reasons. - void reset() { previous = 0; } // Inlined for performance reasons. - ICE_API void swap(ReadEncaps&); + void reset() { previous = 0; } // Inlined for performance reasons. + ICE_API void swap(ReadEncaps&); - Container::size_type start; - Ice::Int sz; + Container::size_type start; + Ice::Int sz; - Ice::Byte encodingMajor; - Ice::Byte encodingMinor; + Ice::Byte encodingMajor; + Ice::Byte encodingMinor; - ReadEncaps* previous; + ReadEncaps* previous; }; class WriteEncaps : private ::IceUtil::noncopyable { public: - WriteEncaps() : writeIndex(0), previous(0) { } // Inlined for performance reasons. - ~WriteEncaps() { } // Inlined for performance reasons. + WriteEncaps() : writeIndex(0), previous(0) { } // Inlined for performance reasons. + ~WriteEncaps() { } // Inlined for performance reasons. - void reset() { writeIndex = 0; previous = 0; } // Inlined for performance reasons. - ICE_API void swap(WriteEncaps&); + void reset() { writeIndex = 0; previous = 0; } // Inlined for performance reasons. + ICE_API void swap(WriteEncaps&); - Container::size_type start; + Container::size_type start; - Ice::Int writeIndex; + Ice::Int writeIndex; - WriteEncaps* previous; + WriteEncaps* previous; }; ReadEncaps* _currentReadEncaps; @@ -651,10 +651,10 @@ private: struct SeqData { - SeqData(int, int); - int numElements; - int minSize; - SeqData* previous; + SeqData(int, int); + int numElements; + int minSize; + SeqData* previous; }; SeqData* _seqDataStack; }; |