Skip to content

Commit

Permalink
protobuf/echo/Serialization: Replace MakeSharedOnHeap<MethodDeseriali…
Browse files Browse the repository at this point in the history
…zerDummy> with deserializerFactory.MakeDummyDeserializer
  • Loading branch information
richardapeters committed Oct 25, 2023
1 parent aa91ca8 commit f7c6f44
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions protobuf/echo/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ namespace services
return false;
}

infra::SharedPtr<MethodDeserializer> MethodDeserializerFactory::MakeDummyDeserializer(Echo& echo)
{
using Deserializer = MethodDeserializerDummy;

auto memory = DeserializerMemory(sizeof(Deserializer));
auto deserializer = new (memory->begin()) Deserializer(echo);
return infra::MakeContainedSharedObject(*deserializer, memory);
}

infra::SharedPtr<infra::ByteRange> MethodDeserializerFactory::OnHeap::DeserializerMemory(uint32_t size)
{
auto m = reinterpret_cast<uint8_t*>(malloc(size));
Expand Down
4 changes: 3 additions & 1 deletion protobuf/echo/Serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ namespace services

template<class Message, class... Args>
infra::SharedPtr<MethodDeserializer> MakeDeserializer(const infra::Function<void(Args...)>& method);

infra::SharedPtr<MethodDeserializer> MakeDummyDeserializer(Echo& echo);
};

template<class MessageList>
Expand All @@ -111,7 +113,7 @@ namespace services
template<>
struct MaxServiceSize<>
{
static constexpr std::size_t maxSize = 0;
static constexpr std::size_t maxSize = sizeof(MethodDeserializerDummy);
};

template<class Front, class... Tail>
Expand Down
2 changes: 1 addition & 1 deletion protobuf/echo/test_doubles/ServiceStub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace services
}));
default:
errorPolicy.MethodNotFound(serviceId, methodId);
return infra::MakeSharedOnHeap<services::MethodDeserializerDummy>(Rpc());
return deserializerfactory.MakeDummyDeserializer(Rpc());
}
}

Expand Down
2 changes: 1 addition & 1 deletion protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ namespace application

printer.Print(R"( default:
errorPolicy.MethodNotFound(serviceId, methodId);
return infra::MakeSharedOnHeap<services::MethodDeserializerDummy>(Rpc());
return deserializerfactory.MakeDummyDeserializer(Rpc());
)");

printer.Print("}\n");
Expand Down

0 comments on commit f7c6f44

Please sign in to comment.