void IPC::setMessageHeaderID(MessageType& message, const uint64_t id) { const auto header_field = message.GetDescriptor()->FindFieldByName("header"); auto reflection = message.GetReflection(); auto header_message = reflection->MutableMessage(&message, header_field); if (header_message->GetTypeName() != IPC::MessageHeader::default_instance().GetTypeName()) { throw std::runtime_error("unknown message header type"); } auto header = reinterpret_cast<IPC::MessageHeader*>(header_message); header->set_id(id); }
uint64_t IPC::getMessageHeaderID(const MessageType& message) { const auto header_field = message.GetDescriptor()->FindFieldByName("header"); const auto reflection = message.GetReflection(); const auto& header_message = reflection->GetMessage(message, header_field); if (header_message.GetTypeName() != IPC::MessageHeader::default_instance().GetTypeName()) { throw std::runtime_error("unknown message header type"); } const auto header = reinterpret_cast<const IPC::MessageHeader&>(header_message); return header.id(); }