Skip to content

Commit

Permalink
Update FormatType in C++ (#2596)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Aug 1, 2024
1 parent c2d334e commit 41102d0
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 177 deletions.
2 changes: 1 addition & 1 deletion cpp/include/Ice/AsyncResponseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace IceInternal

void sendResponse(
std::function<void(Ice::OutputStream*)> marshal,
Ice::FormatType format = Ice::FormatType::DefaultFormat) noexcept
std::optional<Ice::FormatType> format = std::nullopt) noexcept
{
// It is critical to only call the _sendResponse function only once. Calling it multiple times results in an
// incorrect dispatch count.
Expand Down
4 changes: 0 additions & 4 deletions cpp/include/Ice/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ namespace Ice
*/
enum class FormatType : std::uint8_t
{
/**
* Indicates that no preference was specified.
*/
DefaultFormat,
/**
* A minimal format that eliminates the possibility for slicing unrecognized types.
*/
Expand Down
10 changes: 5 additions & 5 deletions cpp/include/Ice/OutgoingAsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ namespace IceInternal
void invoke(
std::string_view,
Ice::OperationMode,
Ice::FormatType,
std::optional<Ice::FormatType>,
const Ice::Context&,
std::function<void(Ice::OutputStream*)>);
void throwUserException();

Ice::OutputStream* startWriteParams(Ice::FormatType format)
Ice::OutputStream* startWriteParams(std::optional<Ice::FormatType> format)
{
_os.startEncapsulation(_encoding, format);
return &_os;
Expand Down Expand Up @@ -294,7 +294,7 @@ namespace IceInternal
void invoke(
std::string_view operation,
Ice::OperationMode mode,
Ice::FormatType format,
std::optional<Ice::FormatType> format,
const Ice::Context& ctx,
std::function<void(Ice::OutputStream*)> write,
std::function<void(const Ice::UserException&)> userException)
Expand All @@ -312,7 +312,7 @@ namespace IceInternal
void invoke(
std::string_view operation,
Ice::OperationMode mode,
Ice::FormatType format,
std::optional<Ice::FormatType> format,
const Ice::Context& ctx,
std::function<void(Ice::OutputStream*)> write,
std::function<void(const Ice::UserException&)> userException,
Expand All @@ -335,7 +335,7 @@ namespace IceInternal
void invoke(
std::string_view operation,
Ice::OperationMode mode,
Ice::FormatType format,
std::optional<Ice::FormatType> format,
const Ice::Context& ctx,
std::function<void(Ice::OutputStream*)> write,
std::function<void(const Ice::UserException&)> userException)
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/OutgoingResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace Ice
ICE_API OutgoingResponse makeOutgoingResponse(
std::function<void(OutputStream*)> marshal,
const Current& current,
FormatType format = FormatType::DefaultFormat) noexcept;
std::optional<FormatType> format = std::nullopt) noexcept;

/**
* Create an OutgoingResponse object with the Ok reply status and an empty payload.
Expand Down
36 changes: 10 additions & 26 deletions cpp/include/Ice/OutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Buffer.h"
#include "CommunicatorF.h"
#include "Ice/Format.h"
#include "Ice/StringConverter.h"
#include "Ice/Version.h"
#include "InstanceF.h"
#include "SlicedDataF.h"
Expand Down Expand Up @@ -36,9 +37,8 @@ namespace Ice
typedef size_t size_type;

/**
* Constructs an OutputStream using the latest encoding version, the default format for
* class encoding, and the process string converters. You can supply a communicator later
* by calling initialize().
* Constructs an OutputStream using the latest encoding version, the compact format for
* class encoding, and the process string converters.
*/
OutputStream();

Expand Down Expand Up @@ -111,20 +111,6 @@ namespace Ice
*/
void clear();

/// \cond INTERNAL
//
// Must return Instance*, because we don't hold an InstancePtr for
// optimization reasons (see comments below).
//
IceInternal::Instance* instance() const { return _instance; } // Inlined for performance reasons.
/// \endcond

/**
* Sets the class encoding format.
* @param format The encoding format.
*/
void setFormat(FormatType format);

/**
* Obtains the closure data associated with this stream.
* @return The data as a void pointer.
Expand Down Expand Up @@ -204,9 +190,10 @@ namespace Ice
* Writes the start of an encapsulation using the given encoding version and
* class encoding format.
* @param encoding The encoding version to use for the encapsulation.
* @param format The class format to use for the encapsulation.
* @param format The class format to use for the encapsulation. nullopt is equivalent to the OutputStream's
* class format.
*/
void startEncapsulation(const EncodingVersion& encoding, FormatType format);
void startEncapsulation(const EncodingVersion& encoding, std::optional<FormatType> format);

/**
* Ends the current encapsulation.
Expand Down Expand Up @@ -805,11 +792,8 @@ namespace Ice
//
void writeConverted(const char*, size_t);

//
// Optimization. The instance may not be deleted while a
// stack-allocated stream still holds it.
//
IceInternal::Instance* _instance;
StringConverterPtr _stringConverter;
WstringConverterPtr _wstringConverter;

//
// The public stream API needs to attach data to a stream.
Expand Down Expand Up @@ -966,7 +950,7 @@ namespace Ice
class Encaps
{
public:
Encaps() : format(FormatType::DefaultFormat), encoder(0), previous(0)
Encaps() : format(FormatType::CompactFormat), encoder(0), previous(0)
{
// Inlined for performance reasons.
}
Expand Down Expand Up @@ -1005,7 +989,7 @@ namespace Ice
//
EncodingVersion _encoding;

FormatType _format;
FormatType _format; // TODO: make it const

Encaps* _currentEncaps;

Expand Down
10 changes: 7 additions & 3 deletions cpp/src/Ice/CollocatedRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ CollocatedRequestHandler::invokeAsyncRequest(OutgoingAsyncBase* outAsync, int ba
{
fillInValue(os, headerSize, batchRequestCount);
}
traceSend(*os, _logger, _traceLevels);
traceSend(*os, _reference->getInstance(), _logger, _traceLevels);
}

outAsync->attachCollocatedObserver(_adapter, requestId);

InputStream is(os->instance(), os->getEncoding(), *os);
InputStream is(_reference->getInstance().get(), os->getEncoding(), *os);

if (batchRequestCount > 0)
{
Expand Down Expand Up @@ -330,7 +330,11 @@ CollocatedRequestHandler::sendResponse(OutgoingResponse response)
fillInValue(os, 10, static_cast<int32_t>(os->b.size()));
}

InputStream is(os->instance(), os->getEncoding(), *os, true); // Adopting the OutputStream's buffer.
InputStream is(
_reference->getInstance().get(),
os->getEncoding(),
*os,
true); // Adopting the OutputStream's buffer.
is.pos(sizeof(replyHdr) + 4);

if (_traceLevels->protocol >= 1)
Expand Down
10 changes: 5 additions & 5 deletions cpp/src/Ice/ConnectionI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,7 @@ Ice::ConnectionI::validate(SocketOperation operation)
static_cast<uint8_t>(0)); // Compression status (always zero for validate connection).
_writeStream.write(headerSize); // Message size.
_writeStream.i = _writeStream.b.begin();
traceSend(_writeStream, _logger, _traceLevels);
traceSend(_writeStream, _instance, _logger, _traceLevels);
}

if (_observer)
Expand Down Expand Up @@ -2665,7 +2665,7 @@ Ice::ConnectionI::sendNextMessages(vector<OutgoingMessage>& callbacks)
OutputStream stream(_instance.get(), Ice::currentProtocolEncoding);
doCompress(*message->stream, stream);

traceSend(*message->stream, _logger, _traceLevels);
traceSend(*message->stream, _instance, _logger, _traceLevels);

message->adopt(&stream); // Adopt the compressed stream.
message->stream->i = message->stream->b.begin();
Expand Down Expand Up @@ -2695,7 +2695,7 @@ Ice::ConnectionI::sendNextMessages(vector<OutgoingMessage>& callbacks)
copy(p, p + sizeof(int32_t), message->stream->b.begin() + 10);
}
message->stream->i = message->stream->b.begin();
traceSend(*message->stream, _logger, _traceLevels);
traceSend(*message->stream, _instance, _logger, _traceLevels);

#ifdef ICE_HAS_BZIP2
}
Expand Down Expand Up @@ -2782,7 +2782,7 @@ Ice::ConnectionI::sendMessage(OutgoingMessage& message)
doCompress(*message.stream, stream);
stream.i = stream.b.begin();

traceSend(*message.stream, _logger, _traceLevels);
traceSend(*message.stream, _instance, _logger, _traceLevels);

if (_observer)
{
Expand Down Expand Up @@ -2833,7 +2833,7 @@ Ice::ConnectionI::sendMessage(OutgoingMessage& message)
}
message.stream->i = message.stream->b.begin();

traceSend(*message.stream, _logger, _traceLevels);
traceSend(*message.stream, _instance, _logger, _traceLevels);

if (_observer)
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/EndpointFactoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ IceInternal::EndpointFactoryManager::create(const string& str, bool oaEndpoint)
OutputStream bs(_instance.get(), Ice::currentProtocolEncoding);
bs.write(ue->type());
ue->streamWrite(&bs);
InputStream is(bs.instance(), bs.getEncoding(), bs);
InputStream is(_instance.get(), bs.getEncoding(), bs);
short type;
is.read(type);
is.startEncapsulation();
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/OpaqueEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ OpaqueEndpointInfoI::OpaqueEndpointInfoI(int16_t type, const Ice::EncodingVersio
void
IceInternal::OpaqueEndpointI::streamWrite(OutputStream* s) const
{
s->startEncapsulation(_rawEncoding, FormatType::DefaultFormat);
s->startEncapsulation(_rawEncoding, nullopt);
s->writeBlob(_rawBytes);
s->endEncapsulation();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/OutgoingAsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ void
OutgoingAsync::invoke(
string_view operation,
OperationMode mode,
FormatType format,
optional<FormatType> format,
const Context& context,
function<void(OutputStream*)> write)
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/OutgoingResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ OutgoingResponse
Ice::makeOutgoingResponse(
std::function<void(OutputStream*)> marshal,
const Current& current,
FormatType format) noexcept
std::optional<FormatType> format) noexcept
{
assert(marshal);
OutputStream ostr(current.adapter->getCommunicator(), Ice::currentProtocolEncoding);
Expand Down
Loading

0 comments on commit 41102d0

Please sign in to comment.