Skip to content

Commit

Permalink
Place topic before payload
Browse files Browse the repository at this point in the history
  • Loading branch information
sfodagain committed Jan 29, 2025
1 parent 47b07b2 commit 8555c77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
34 changes: 17 additions & 17 deletions include/aws/iot/MqttRequestResponseClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,53 +121,53 @@ namespace Aws
/**
* Default constructor
*/
IncomingPublishEvent() : m_payload(), m_topic()
IncomingPublishEvent() : m_topic(), m_payload()
{
AWS_ZERO_STRUCT(m_payload);
AWS_ZERO_STRUCT(m_topic);
AWS_ZERO_STRUCT(m_payload);
}

/**
* Sets the message payload associated with this event. The event does not own this payload.
* Sets the message response topic associated with this event. The event does not own this topic.
*
* @param payload the message payload associated with this event
* @param topic the message response topic associated with this event
* @return reference to this
*/
IncomingPublishEvent &WithPayload(Aws::Crt::ByteCursor payload)
IncomingPublishEvent &WithTopic(Aws::Crt::ByteCursor topic)
{
m_payload = payload;
m_topic = topic;
return *this;
}

/**
* Sets the message response topic associated with this event. The event does not own this topic.
* Sets the message payload associated with this event. The event does not own this payload.
*
* @param topic the message response topic associated with this event
* @param payload the message payload associated with this event
* @return reference to this
*/
IncomingPublishEvent &WithTopic(Aws::Crt::ByteCursor topic)
IncomingPublishEvent &WithPayload(Aws::Crt::ByteCursor payload)
{
m_topic = topic;
m_payload = payload;
return *this;
}

/**
* Gets the message payload associated with this event.
* Gets the message response topic associated with this event.
*
* @return the message payload associated with this event
* @return the message response topic associated with this event
*/
Aws::Crt::ByteCursor GetPayload() const { return m_payload; }
Aws::Crt::ByteCursor GetTopic() const { return m_topic; }

/**
* Gets the message response topic associated with this event.
* Gets the message payload associated with this event.
*
* @return the message response topic associated with this event
* @return the message payload associated with this event
*/
Aws::Crt::ByteCursor GetTopic() const { return m_topic; }
Aws::Crt::ByteCursor GetPayload() const { return m_payload; }

private:
Aws::Crt::ByteCursor m_payload;
Aws::Crt::ByteCursor m_topic;
Aws::Crt::ByteCursor m_payload;
};

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/MqttRequestResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ struct ResponseTracker

struct TestPublishEvent
{
Aws::Crt::String payload;
Aws::Crt::String topic;
Aws::Crt::String payload;
};

struct TestState
Expand Down Expand Up @@ -174,13 +174,13 @@ static void s_onIncomingPublishEvent(Aws::Iot::RequestResponse::IncomingPublishE
{
std::unique_lock<std::mutex> lock(state->lock);

auto payloadCursor = event.GetPayload();
Aws::Crt::String payloadAsString((const char *)payloadCursor.ptr, payloadCursor.len);

auto topicCursor = event.GetTopic();
Aws::Crt::String topicAsString((const char *)topicCursor.ptr, topicCursor.len);

state->incomingPublishEvents.push_back({std::move(payloadAsString), std::move(topicAsString)});
auto payloadCursor = event.GetPayload();
Aws::Crt::String payloadAsString((const char *)payloadCursor.ptr, payloadCursor.len);

state->incomingPublishEvents.push_back({std::move(topicAsString), std::move(payloadAsString)});
}
state->signal.notify_one();
}
Expand Down Expand Up @@ -1088,7 +1088,7 @@ static int s_doShadowUpdatedStreamIncomingPublishTest(Aws::Crt::Allocator *alloc
s_waitForIncomingPublishWithPredicate(
&state,
[&uuid](const TestPublishEvent &publishEvent)
{ return publishEvent.payload == Aws::Crt::String(s_publishPayload) && publishEvent.topic == uuid; });
{ return publishEvent.topic == uuid && publishEvent.payload == Aws::Crt::String(s_publishPayload); });

return AWS_OP_SUCCESS;
}
Expand Down

0 comments on commit 8555c77

Please sign in to comment.