Complete batch receive other feature of C client #254
Conversation
| * 1. When it's callback call result is `ResultOk`, `*msg` will point to the memory that | ||
| * is allocated internally. You have to call `pulsar_messages_free` to free it. | ||
| * 2. If callback call result is not `ResultOk`, `*msg` will is nullptr. |
There was a problem hiding this comment.
| * 1. When it's callback call result is `ResultOk`, `*msg` will point to the memory that | |
| * is allocated internally. You have to call `pulsar_messages_free` to free it. | |
| * 2. If callback call result is not `ResultOk`, `*msg` will is nullptr. | |
| * 1. When the result in the callback is `ResultOk`, `*msg` will point to the memory that | |
| * is allocated internally. You have to call `pulsar_messages_free` to free it. | |
| * 2. If the result in the callback is not `ResultOk`, `*msg` will be nullptr. |
Fix wrong semantic.
And I think this description is wrong. Because the asynchronous API does not have a msg parameter.
There was a problem hiding this comment.
This msg mean callback result msg.
There was a problem hiding this comment.
Then msg is pulsar_messages_t*, not pulsar_messages_t**. We should not use *msg here, because now *msg is pulsar_messages_t, which is a struct and could never be nullptr.
There was a problem hiding this comment.
because now *msg is pulsar_messages_t, which is a struct and could never be nullptr.
Isn't *msg a pointer representing pulsar_messages_t object?
There was a problem hiding this comment.
No. Let's review the basic knowledge of C first. Given the pointer int* p, *p is the int object that p points to, while p is the pointer that points to an int.
Then, see the synchronous batch receive method:
PULSAR_PUBLIC pulsar_result pulsar_consumer_batch_receive(pulsar_consumer_t *consumer,
pulsar_messages_t **msgs);msgsis a pointer that points topulsar_messages_t*, which is a pointer that points to apulsar_messages_tobject.*msgsis a pointer thatmsgspoints to, i.e.*msgsis the pointer that points to apulsar_messages_tobject.
Let's see the callback in this PR.
typedef void (*pulsar_batch_receive_callback)(pulsar_result result, pulsar_messages_t *msg, void *ctx);msgis a pointer that points to apulsar_messages_tobject.*msgis thepulsar_messages_tobject thatmsgpoints to.
There was a problem hiding this comment.
I see.
Isn't *msg a pointer representing pulsar_messages_t object?
This statement is wrong and should be: msg is a pointer representing pulsar_messages_t object.
Let's get back to the discussion. The flow code.
pulsar_messages_t *msgs = nullptr;
if (result == pulsar::ResultOk) {
msgs = new pulsar_messages_t;
// set data.
}
callback((pulsar_result)result, msgs, ctx);msgsis a pointer that points to a pulsar_messages_t object.*msgsis the pulsar_messages_t object that msg points to.
So, I pass a msgs is not *msgs. What I passed in was a pointer, right? I can pass in a nullptr.
I need change note
- * 1. When the result in the callback is `ResultOk`, `*msg` in the callback will point to the memory that
- * is allocated internally. You have to call `pulsar_messages_free` to free it.
- * 2. If the result in the callback is not `ResultOk`, `*msg` in the callback will is nullptr.
+ * 1. When the result in the callback is `ResultOk`, `msg` in the callback will point to the memory that
+ * is allocated internally. You have to call `pulsar_messages_free` to free it.
+ * 2. If the result in the callback is not `ResultOk`, `msg` in the callback will is nullptr.There was a problem hiding this comment.
The changes you made is correct. BTW, will is -> will be.
Master Issue: #252
Motivation
Complete batch receive other feature.
Modifications
Verifying this change
Documentation
doc-required(Your PR needs to update docs and you will update later)
doc-not-needed(Please explain why)
doc(Your PR contains doc changes)
doc-complete(Docs have been already added)