-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Uuid support in mock cluster #4591
Conversation
25b5960
to
4fa605c
Compare
for (i = 0; i < 16; i += 2) { | ||
uint16_t rand_uint16 = (uint16_t)rd_jitter(0, INT16_MAX - 1); | ||
/* No need to convert endianess here because it's still only | ||
* a random value. */ | ||
rand_values_app = (unsigned char *)&rand_uint16; | ||
rand_values_bytes[i] |= rand_values_app[0]; | ||
rand_values_bytes[i + 1] |= rand_values_app[1]; | ||
} | ||
|
||
rand_values_bytes[6] &= 0x0f; /* clear version */ | ||
rand_values_bytes[6] |= 0x40; /* version 4 */ | ||
rand_values_bytes[8] &= 0x3f; /* clear variant */ | ||
rand_values_bytes[8] |= 0x80; /* IETF variant */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move this to rdrand.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It generates a Uuid, all the code for a Uuid is here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I can move it to a rdkafka_uuid.h
and rdkafka_uuid.c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was talking about the generic part related to random bytes generation here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding rdkafka_uuid.h and rdkafka_uuid.c, we can have them but don't do it for now. Let's do it later when we we won't have much conflicts with other ongoing dev work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move this to rdrand.h
here the random value is generated in rd_jitter
that is already in rdrand.h
the rest is code related to Uuid
src/rdkafka_int.h
Outdated
RD_EXPORT rd_kafka_Uuid_t *rd_kafka_Uuid_random(); | ||
|
||
RD_EXPORT const char *rd_kafka_Uuid_str(const rd_kafka_Uuid_t *uuid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can be in proto.h and the definitions should be in proto.c as everything internal related to Uuid is present there.
src/rdkafka.c
Outdated
* | ||
* @remark Must be freed after use using rd_kafka_Uuid_destroy(). | ||
*/ | ||
rd_kafka_Uuid_t *rd_kafka_Uuid_random() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we returning a pointer instead of a value here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, better to return the struct, its usage is internal only
for (i = 0; i < 16; i += 2) { | ||
uint16_t rand_uint16 = (uint16_t)rd_jitter(0, INT16_MAX - 1); | ||
/* No need to convert endianess here because it's still only | ||
* a random value. */ | ||
rand_values_app = (unsigned char *)&rand_uint16; | ||
rand_values_bytes[i] |= rand_values_app[0]; | ||
rand_values_bytes[i + 1] |= rand_values_app[1]; | ||
} | ||
|
||
rand_values_bytes[6] &= 0x0f; /* clear version */ | ||
rand_values_bytes[6] |= 0x40; /* version 4 */ | ||
rand_values_bytes[8] &= 0x3f; /* clear variant */ | ||
rand_values_bytes[8] |= 0x80; /* IETF variant */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was talking about the generic part related to random bytes generation here.
* | ||
* @remark Must be freed after use using rd_kafka_Uuid_destroy(). | ||
*/ | ||
rd_kafka_Uuid_t rd_kafka_Uuid_random() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to rdkafka_proto.h where all the other internal functions related to Uuid are present
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is just a header we cannot move all the implementation there, we can refactor to its own file
* | ||
* @remark Must be freed after use. | ||
*/ | ||
const char *rd_kafka_Uuid_str(const rd_kafka_Uuid_t *uuid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to rdkafka_proto.h where all the other internal functions related to Uuid are present
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
for (i = 0; i < 16; i += 2) { | ||
uint16_t rand_uint16 = (uint16_t)rd_jitter(0, INT16_MAX - 1); | ||
/* No need to convert endianess here because it's still only | ||
* a random value. */ | ||
rand_values_app = (unsigned char *)&rand_uint16; | ||
rand_values_bytes[i] |= rand_values_app[0]; | ||
rand_values_bytes[i + 1] |= rand_values_app[1]; | ||
} | ||
|
||
rand_values_bytes[6] &= 0x0f; /* clear version */ | ||
rand_values_bytes[6] |= 0x40; /* version 4 */ | ||
rand_values_bytes[8] &= 0x3f; /* clear variant */ | ||
rand_values_bytes[8] |= 0x80; /* IETF variant */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding rdkafka_uuid.h and rdkafka_uuid.c, we can have them but don't do it for now. Let's do it later when we we won't have much conflicts with other ongoing dev work.
0011cf9
to
b5fe084
Compare
b5fe084
to
69c0311
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
also adds the possibility to generate pseudo-random Uuids
No description provided.