Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP #1681 > support/v5.12] [core] Protobuf Publisher Send should return the actual send size. #1684

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ecal/core/include/ecal/msg/protobuf/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ namespace eCAL
size_t Send(const T& msg_, long long time_, long long acknowledge_timeout_ms_)
{
CPayload payload{ msg_ };
eCAL::CPublisher::Send(payload, time_, acknowledge_timeout_ms_);
return(0);
return eCAL::CPublisher::Send(payload, time_, acknowledge_timeout_ms_);
}


Expand Down
23 changes: 17 additions & 6 deletions testing/ecal/pubsub_proto_test/src/proto_subscriber_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,12 +50,20 @@ class ProtoSubscriberTest : public ::testing::Test {
eCAL::Finalize();
}

void SendPerson(eCAL::protobuf::CPublisher<pb::People::Person>& pub)
size_t SendPerson(eCAL::protobuf::CPublisher<pb::People::Person>& pub)
{
pb::People::Person p;
p.set_id(1);
p.set_name("Max");
pub.Send(p);
return pub.Send(p);
}

size_t GetPersonSize()
{
#if GOOGLE_PROTOBUF_VERSION >= 3001000
return static_cast<size_t>(p.ByteSizeLong());
#else
return static_cast<size_t>(p.ByteSize());
#endif
}

void OnPerson(const char*, const pb::People::Person&, long long, long long)
Expand All @@ -64,6 +72,9 @@ class ProtoSubscriberTest : public ::testing::Test {
}

std::atomic<int> received_callbacks;

private:
pb::People::Person p;
};

TEST_F(ProtoSubscriberTest, SendReceive)
Expand All @@ -78,11 +89,11 @@ TEST_F(ProtoSubscriberTest, SendReceive)

std::this_thread::sleep_for(std::chrono::milliseconds(2000));

SendPerson(person_pub);
auto bytes_send = SendPerson(person_pub);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
// assert that the OnPerson callback has been called once.
ASSERT_EQ(1, received_callbacks);

ASSERT_EQ(bytes_send, GetPersonSize());
}


Expand Down
Loading