Skip to content

Commit

Permalink
Fix empty bundle payload
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu committed Apr 18, 2024
1 parent 7bf1efd commit dc76bc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static com.google.udmi.util.JsonUtil.fromString;
import static com.google.udmi.util.JsonUtil.parseJson;
import static com.google.udmi.util.JsonUtil.stringify;
import static com.google.udmi.util.JsonUtil.stringifyTerse;
import static java.lang.String.format;
import static java.util.Objects.isNull;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -525,6 +526,13 @@ public Bundle(Map<String, String> attributes, Object message) {
this.attributesMap = attributes;
this.message = message;
}

public byte[] getSendBytes() {
checkState(message == null || payload == null, "no message or payload");
checkState(!(message != null && payload != null), "no message or payload");
String send = ifNotNullGet(message, m -> stringifyTerse(message), payload);
return send.getBytes();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private String makeBrokerUrl(EndpointConfiguration endpoint) {

private MqttMessage makeMqttMessage(Bundle bundle) {
MqttMessage message = new MqttMessage();
message.setPayload(bundle.payload.getBytes());
message.setPayload(bundle.getSendBytes());
return message;
}

Expand Down

0 comments on commit dc76bc0

Please sign in to comment.