Skip to content

Commit 8b7b440

Browse files
committed
Switch off Crt::Variant temporarily
1 parent 3291633 commit 8b7b440

4 files changed

Lines changed: 244 additions & 335 deletions

File tree

eventstream_rpc/include/aws/eventstreamrpc/EventStreamClient.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <aws/crt/JsonObject.h>
1313
#include <aws/crt/StlAllocator.h>
1414
#include <aws/crt/Types.h>
15-
#include <aws/crt/Variant.h>
1615
#include <aws/crt/io/SocketOptions.h>
1716
#include <aws/crt/io/TlsOptions.h>
1817

@@ -369,15 +368,39 @@ namespace Aws
369368

370369
enum ResultType
371370
{
371+
NONE,
372372
OPERATION_RESPONSE,
373373
OPERATION_ERROR,
374374
RPC_ERROR
375375
};
376376

377-
using EventstreamResultVariantType =
378-
Crt::Variant<Crt::ScopedResource<AbstractShapeBase>, Crt::ScopedResource<OperationError>, RpcError>;
377+
class AWS_EVENTSTREAMRPC_API EventstreamResultVariantType
378+
{
379+
public:
380+
EventstreamResultVariantType();
381+
explicit EventstreamResultVariantType(Crt::ScopedResource<AbstractShapeBase> &&modeledResult) noexcept;
382+
explicit EventstreamResultVariantType(Crt::ScopedResource<OperationError> &&modeledError) noexcept;
383+
explicit EventstreamResultVariantType(RpcError rpcError) noexcept;
384+
EventstreamResultVariantType(EventstreamResultVariantType &&rhs) noexcept;
385+
~EventstreamResultVariantType() = default;
386+
387+
EventstreamResultVariantType &operator=(EventstreamResultVariantType &&rhs) noexcept;
388+
389+
ResultType GetType() const { return m_type; }
390+
391+
AbstractShapeBase *GetModeledResult() const;
379392

380-
AWS_EVENTSTREAMRPC_API ResultType ResultVariantToResultType(const EventstreamResultVariantType &resultVariant);
393+
OperationError *GetModeledError() const;
394+
395+
RpcError GetRpcError() const;
396+
397+
private:
398+
ResultType m_type;
399+
400+
Crt::ScopedResource<AbstractShapeBase> m_modeledResult;
401+
Crt::ScopedResource<OperationError> m_modeledError;
402+
RpcError m_rpcError;
403+
};
381404

382405
using ExpectedResponseFactory = std::function<
383406
Crt::ScopedResource<AbstractShapeBase>(const Crt::StringView &payload, Crt::Allocator *allocator)>;

eventstream_rpc/source/EventStreamClient.cpp

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,20 +2383,66 @@ namespace Aws
23832383
std::move(onMessageFlushCallback));
23842384
}
23852385

2386-
ResultType ResultVariantToResultType(const EventstreamResultVariantType &resultVariant)
2386+
EventstreamResultVariantType::EventstreamResultVariantType()
2387+
: m_type(ResultType::NONE), m_modeledResult(nullptr), m_modeledError(nullptr),
2388+
m_rpcError({EventStreamRpcStatusCode::EVENT_STREAM_RPC_SUCCESS, AWS_ERROR_SUCCESS})
23872389
{
2388-
if (resultVariant.holds_alternative<Crt::ScopedResource<AbstractShapeBase>>())
2389-
{
2390-
return OPERATION_RESPONSE;
2391-
}
2392-
else if (resultVariant.holds_alternative<Crt::ScopedResource<OperationError>>())
2393-
{
2394-
return OPERATION_ERROR;
2395-
}
2396-
else
2390+
}
2391+
2392+
EventstreamResultVariantType::EventstreamResultVariantType(
2393+
Crt::ScopedResource<AbstractShapeBase> &&modeledResult) noexcept
2394+
: m_type(ResultType::OPERATION_RESPONSE), m_modeledResult(std::move(modeledResult)),
2395+
m_modeledError(nullptr),
2396+
m_rpcError({EventStreamRpcStatusCode::EVENT_STREAM_RPC_SUCCESS, AWS_ERROR_SUCCESS})
2397+
{
2398+
}
2399+
2400+
EventstreamResultVariantType::EventstreamResultVariantType(
2401+
Crt::ScopedResource<OperationError> &&modeledError) noexcept
2402+
: m_type(ResultType::OPERATION_ERROR), m_modeledResult(nullptr), m_modeledError(std::move(modeledError)),
2403+
m_rpcError({EventStreamRpcStatusCode::EVENT_STREAM_RPC_SUCCESS, AWS_ERROR_SUCCESS})
2404+
{
2405+
}
2406+
2407+
EventstreamResultVariantType::EventstreamResultVariantType(RpcError rpcError) noexcept
2408+
: m_type(ResultType::RPC_ERROR), m_modeledResult(nullptr), m_modeledError(nullptr), m_rpcError(rpcError)
2409+
{
2410+
}
2411+
2412+
EventstreamResultVariantType::EventstreamResultVariantType(EventstreamResultVariantType &&rhs) noexcept
2413+
: m_type(rhs.m_type), m_modeledResult(std::move(rhs.m_modeledResult)),
2414+
m_modeledError(std::move(rhs.m_modeledError)), m_rpcError(rhs.m_rpcError)
2415+
{
2416+
}
2417+
2418+
EventstreamResultVariantType &EventstreamResultVariantType::operator=(
2419+
EventstreamResultVariantType &&rhs) noexcept
2420+
{
2421+
if (this != &rhs)
23972422
{
2398-
return RPC_ERROR;
2423+
m_type = rhs.m_type;
2424+
m_modeledResult = std::move(rhs.m_modeledResult);
2425+
m_modeledError = std::move(rhs.m_modeledError);
2426+
m_rpcError = rhs.m_rpcError;
23992427
}
2428+
2429+
return *this;
2430+
}
2431+
2432+
AbstractShapeBase *EventstreamResultVariantType::GetModeledResult() const
2433+
{
2434+
return m_modeledResult.get();
2435+
}
2436+
2437+
OperationError *EventstreamResultVariantType::GetModeledError() const
2438+
{
2439+
return m_modeledError.get();
24002440
}
2441+
2442+
RpcError EventstreamResultVariantType::GetRpcError() const
2443+
{
2444+
return m_rpcError;
2445+
}
2446+
24012447
} /* namespace Eventstreamrpc */
24022448
} // namespace Aws

eventstream_rpc/tests/include/awstest/EchoTestRpcModel.h

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -686,21 +686,17 @@ namespace Awstest
686686
GetAllProductsResult(EventstreamResultVariantType &&result) noexcept : m_result(std::move(result)) {}
687687
GetAllProductsResponse *GetOperationResponse() const noexcept
688688
{
689-
return static_cast<GetAllProductsResponse *>(
690-
std::get<Aws::Crt::ScopedResource<AbstractShapeBase>>(m_result).get());
689+
return static_cast<GetAllProductsResponse *>(m_result.GetModeledResult());
691690
}
692691

693692
/**
694693
* @return true if the response is associated with an expected response;
695694
* false if the response is associated with an error.
696695
*/
697696
operator bool() const noexcept { return GetResultType() == OPERATION_RESPONSE; }
698-
OperationError *GetOperationError() const noexcept
699-
{
700-
return std::get<Aws::Crt::ScopedResource<OperationError>>(m_result).get();
701-
}
702-
RpcError GetRpcError() const noexcept { return std::get<RpcError>(m_result); }
703-
ResultType GetResultType() const noexcept { return ResultVariantToResultType(m_result); }
697+
OperationError *GetOperationError() const noexcept { return m_result.GetModeledError(); }
698+
RpcError GetRpcError() const noexcept { return m_result.GetRpcError(); }
699+
ResultType GetResultType() const noexcept { return m_result.GetType(); }
704700

705701
private:
706702
EventstreamResultVariantType m_result;
@@ -740,21 +736,17 @@ namespace Awstest
740736
CauseServiceErrorResult(EventstreamResultVariantType &&result) noexcept : m_result(std::move(result)) {}
741737
CauseServiceErrorResponse *GetOperationResponse() const noexcept
742738
{
743-
return static_cast<CauseServiceErrorResponse *>(
744-
std::get<Aws::Crt::ScopedResource<AbstractShapeBase>>(m_result).get());
739+
return static_cast<CauseServiceErrorResponse *>(m_result.GetModeledResult());
745740
}
746741

747742
/**
748743
* @return true if the response is associated with an expected response;
749744
* false if the response is associated with an error.
750745
*/
751746
operator bool() const noexcept { return GetResultType() == OPERATION_RESPONSE; }
752-
OperationError *GetOperationError() const noexcept
753-
{
754-
return std::get<Aws::Crt::ScopedResource<OperationError>>(m_result).get();
755-
}
756-
RpcError GetRpcError() const noexcept { return std::get<RpcError>(m_result); }
757-
ResultType GetResultType() const noexcept { return ResultVariantToResultType(m_result); }
747+
OperationError *GetOperationError() const noexcept { return m_result.GetModeledError(); }
748+
RpcError GetRpcError() const noexcept { return m_result.GetRpcError(); }
749+
ResultType GetResultType() const noexcept { return m_result.GetType(); }
758750

759751
private:
760752
EventstreamResultVariantType m_result;
@@ -843,21 +835,17 @@ namespace Awstest
843835
CauseStreamServiceToErrorResult(EventstreamResultVariantType &&result) noexcept : m_result(std::move(result)) {}
844836
EchoStreamingResponse *GetOperationResponse() const noexcept
845837
{
846-
return static_cast<EchoStreamingResponse *>(
847-
std::get<Aws::Crt::ScopedResource<AbstractShapeBase>>(m_result).get());
838+
return static_cast<EchoStreamingResponse *>(m_result.GetModeledResult());
848839
}
849840

850841
/**
851842
* @return true if the response is associated with an expected response;
852843
* false if the response is associated with an error.
853844
*/
854845
operator bool() const noexcept { return GetResultType() == OPERATION_RESPONSE; }
855-
OperationError *GetOperationError() const noexcept
856-
{
857-
return std::get<Aws::Crt::ScopedResource<OperationError>>(m_result).get();
858-
}
859-
RpcError GetRpcError() const noexcept { return std::get<RpcError>(m_result); }
860-
ResultType GetResultType() const noexcept { return ResultVariantToResultType(m_result); }
846+
OperationError *GetOperationError() const noexcept { return m_result.GetModeledError(); }
847+
RpcError GetRpcError() const noexcept { return m_result.GetRpcError(); }
848+
ResultType GetResultType() const noexcept { return m_result.GetType(); }
861849

862850
private:
863851
EventstreamResultVariantType m_result;
@@ -949,21 +937,17 @@ namespace Awstest
949937
EchoStreamMessagesResult(EventstreamResultVariantType &&result) noexcept : m_result(std::move(result)) {}
950938
EchoStreamingResponse *GetOperationResponse() const noexcept
951939
{
952-
return static_cast<EchoStreamingResponse *>(
953-
std::get<Aws::Crt::ScopedResource<AbstractShapeBase>>(m_result).get());
940+
return static_cast<EchoStreamingResponse *>(m_result.GetModeledResult());
954941
}
955942

956943
/**
957944
* @return true if the response is associated with an expected response;
958945
* false if the response is associated with an error.
959946
*/
960947
operator bool() const noexcept { return GetResultType() == OPERATION_RESPONSE; }
961-
OperationError *GetOperationError() const noexcept
962-
{
963-
return std::get<Aws::Crt::ScopedResource<OperationError>>(m_result).get();
964-
}
965-
RpcError GetRpcError() const noexcept { return std::get<RpcError>(m_result); }
966-
ResultType GetResultType() const noexcept { return ResultVariantToResultType(m_result); }
948+
OperationError *GetOperationError() const noexcept { return m_result.GetModeledError(); }
949+
RpcError GetRpcError() const noexcept { return m_result.GetRpcError(); }
950+
ResultType GetResultType() const noexcept { return m_result.GetType(); }
967951

968952
private:
969953
EventstreamResultVariantType m_result;
@@ -1016,21 +1000,17 @@ namespace Awstest
10161000
EchoMessageResult(EventstreamResultVariantType &&result) noexcept : m_result(std::move(result)) {}
10171001
EchoMessageResponse *GetOperationResponse() const noexcept
10181002
{
1019-
return static_cast<EchoMessageResponse *>(
1020-
std::get<Aws::Crt::ScopedResource<AbstractShapeBase>>(m_result).get());
1003+
return static_cast<EchoMessageResponse *>(m_result.GetModeledResult());
10211004
}
10221005

10231006
/**
10241007
* @return true if the response is associated with an expected response;
10251008
* false if the response is associated with an error.
10261009
*/
10271010
operator bool() const noexcept { return GetResultType() == OPERATION_RESPONSE; }
1028-
OperationError *GetOperationError() const noexcept
1029-
{
1030-
return std::get<Aws::Crt::ScopedResource<OperationError>>(m_result).get();
1031-
}
1032-
RpcError GetRpcError() const noexcept { return std::get<RpcError>(m_result); }
1033-
ResultType GetResultType() const noexcept { return ResultVariantToResultType(m_result); }
1011+
OperationError *GetOperationError() const noexcept { return m_result.GetModeledError(); }
1012+
RpcError GetRpcError() const noexcept { return m_result.GetRpcError(); }
1013+
ResultType GetResultType() const noexcept { return m_result.GetType(); }
10341014

10351015
private:
10361016
EventstreamResultVariantType m_result;
@@ -1070,21 +1050,17 @@ namespace Awstest
10701050
GetAllCustomersResult(EventstreamResultVariantType &&result) noexcept : m_result(std::move(result)) {}
10711051
GetAllCustomersResponse *GetOperationResponse() const noexcept
10721052
{
1073-
return static_cast<GetAllCustomersResponse *>(
1074-
std::get<Aws::Crt::ScopedResource<AbstractShapeBase>>(m_result).get());
1053+
return static_cast<GetAllCustomersResponse *>(m_result.GetModeledResult());
10751054
}
10761055

10771056
/**
10781057
* @return true if the response is associated with an expected response;
10791058
* false if the response is associated with an error.
10801059
*/
10811060
operator bool() const noexcept { return GetResultType() == OPERATION_RESPONSE; }
1082-
OperationError *GetOperationError() const noexcept
1083-
{
1084-
return std::get<Aws::Crt::ScopedResource<OperationError>>(m_result).get();
1085-
}
1086-
RpcError GetRpcError() const noexcept { return std::get<RpcError>(m_result); }
1087-
ResultType GetResultType() const noexcept { return ResultVariantToResultType(m_result); }
1061+
OperationError *GetOperationError() const noexcept { return m_result.GetModeledError(); }
1062+
RpcError GetRpcError() const noexcept { return m_result.GetRpcError(); }
1063+
ResultType GetResultType() const noexcept { return m_result.GetType(); }
10881064

10891065
private:
10901066
EventstreamResultVariantType m_result;

0 commit comments

Comments
 (0)