forked from OSchip/llvm-project
[Orc][RPC] Accept both const char* and char* arguments for string serialization.
llvm-svn: 296168
This commit is contained in:
parent
c12a5a7595
commit
630d2639f9
|
@ -142,10 +142,12 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
template <typename ChannelT>
|
||||
class SerializationTraits<ChannelT, std::string, const char *,
|
||||
typename std::enable_if<std::is_base_of<
|
||||
RawByteChannel, ChannelT>::value>::type> {
|
||||
template <typename ChannelT, typename T>
|
||||
class SerializationTraits<ChannelT, std::string, T,
|
||||
typename std::enable_if<
|
||||
std::is_base_of<RawByteChannel, ChannelT>::value &&
|
||||
(std::is_same<T, const char*>::value ||
|
||||
std::is_same<T, char*>::value)>::type> {
|
||||
public:
|
||||
static Error serialize(RawByteChannel &C, const char *S) {
|
||||
return SerializationTraits<ChannelT, std::string, StringRef>::serialize(C,
|
||||
|
|
|
@ -120,6 +120,11 @@ namespace DummyRPCAPI {
|
|||
static const char* getName() { return "IntInt"; }
|
||||
};
|
||||
|
||||
class VoidString : public Function<VoidString, void(std::string)> {
|
||||
public:
|
||||
static const char* getName() { return "VoidString"; }
|
||||
};
|
||||
|
||||
class AllTheTypes
|
||||
: public Function<AllTheTypes,
|
||||
void(int8_t, uint8_t, int16_t, uint16_t, int32_t,
|
||||
|
@ -340,6 +345,46 @@ TEST(DummyRPC, TestAsyncIntIntHandlerMethod) {
|
|||
ServerThread.join();
|
||||
}
|
||||
|
||||
TEST(DummyRPC, TestCallAsyncVoidString) {
|
||||
Queue Q1, Q2;
|
||||
DummyRPCEndpoint Client(Q1, Q2);
|
||||
DummyRPCEndpoint Server(Q2, Q1);
|
||||
|
||||
std::thread ServerThread([&]() {
|
||||
Server.addHandler<DummyRPCAPI::VoidString>(
|
||||
[](const std::string &S) {
|
||||
EXPECT_EQ(S, "hello")
|
||||
<< "Server void(std::string) received unexpected result";
|
||||
});
|
||||
|
||||
// Poke the server to handle the negotiate call.
|
||||
for (int I = 0; I < 4; ++I) {
|
||||
auto Err = Server.handleOne();
|
||||
EXPECT_FALSE(!!Err) << "Server failed to handle call";
|
||||
}
|
||||
});
|
||||
|
||||
{
|
||||
// Make an call using a std::string.
|
||||
auto Err = Client.callB<DummyRPCAPI::VoidString>(std::string("hello"));
|
||||
EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(std::string)";
|
||||
}
|
||||
|
||||
{
|
||||
// Make an call using a std::string.
|
||||
auto Err = Client.callB<DummyRPCAPI::VoidString>(StringRef("hello"));
|
||||
EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(std::string)";
|
||||
}
|
||||
|
||||
{
|
||||
// Make an call using a std::string.
|
||||
auto Err = Client.callB<DummyRPCAPI::VoidString>("hello");
|
||||
EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(string)";
|
||||
}
|
||||
|
||||
ServerThread.join();
|
||||
}
|
||||
|
||||
TEST(DummyRPC, TestSerialization) {
|
||||
Queue Q1, Q2;
|
||||
DummyRPCEndpoint Client(Q1, Q2);
|
||||
|
|
Loading…
Reference in New Issue