Skip to content

Commit

Permalink
renaming to ze_
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Sep 26, 2024
1 parent 02dd32c commit 6147932
Show file tree
Hide file tree
Showing 12 changed files with 373 additions and 325 deletions.
112 changes: 56 additions & 56 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -319,62 +319,62 @@ Primitives
.. autocfunction:: primitives.h::z_slice_len
.. autocfunction:: primitives.h::z_slice_empty
.. autocfunction:: primitives.h::z_slice_is_empty
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_int8
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_int16
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_int32
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_int64
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_uint8
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_uint16
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_uint32
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_uint64
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_float
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_double
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_slice
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_string
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_sequence_begin
.. autocfunction:: serialization.h::z_bytes_reader_deserialize_sequence_end
.. autocfunction:: serialization.h::z_bytes_writer_serialize_int8
.. autocfunction:: serialization.h::z_bytes_writer_serialize_int16
.. autocfunction:: serialization.h::z_bytes_writer_serialize_int32
.. autocfunction:: serialization.h::z_bytes_writer_serialize_int64
.. autocfunction:: serialization.h::z_bytes_writer_serialize_uint8
.. autocfunction:: serialization.h::z_bytes_writer_serialize_uint16
.. autocfunction:: serialization.h::z_bytes_writer_serialize_uint32
.. autocfunction:: serialization.h::z_bytes_writer_serialize_uint64
.. autocfunction:: serialization.h::z_bytes_writer_serialize_float
.. autocfunction:: serialization.h::z_bytes_writer_serialize_double
.. autocfunction:: serialization.h::z_bytes_writer_serialize_slice
.. autocfunction:: serialization.h::z_bytes_writer_serialize_buf
.. autocfunction:: serialization.h::z_bytes_writer_serialize_string
.. autocfunction:: serialization.h::z_bytes_writer_serialize_str
.. autocfunction:: serialization.h::z_bytes_writer_serialize_sequence_begin
.. autocfunction:: serialization.h::z_bytes_writer_serialize_sequence_end
.. autocfunction:: serialization.h::z_bytes_deserialize_into_int8
.. autocfunction:: serialization.h::z_bytes_deserialize_into_int16
.. autocfunction:: serialization.h::z_bytes_deserialize_into_int32
.. autocfunction:: serialization.h::z_bytes_deserialize_into_int64
.. autocfunction:: serialization.h::z_bytes_deserialize_into_uint8
.. autocfunction:: serialization.h::z_bytes_deserialize_into_uint16
.. autocfunction:: serialization.h::z_bytes_deserialize_into_uint32
.. autocfunction:: serialization.h::z_bytes_deserialize_into_uint64
.. autocfunction:: serialization.h::z_bytes_deserialize_into_float
.. autocfunction:: serialization.h::z_bytes_deserialize_into_double
.. autocfunction:: serialization.h::z_bytes_deserialize_into_slice
.. autocfunction:: serialization.h::z_bytes_deserialize_into_string
.. autocfunction:: serialization.h::z_bytes_serialize_from_int8
.. autocfunction:: serialization.h::z_bytes_serialize_from_int16
.. autocfunction:: serialization.h::z_bytes_serialize_from_int32
.. autocfunction:: serialization.h::z_bytes_serialize_from_int64
.. autocfunction:: serialization.h::z_bytes_serialize_from_uint8
.. autocfunction:: serialization.h::z_bytes_serialize_from_uint16
.. autocfunction:: serialization.h::z_bytes_serialize_from_uint32
.. autocfunction:: serialization.h::z_bytes_serialize_from_uint64
.. autocfunction:: serialization.h::z_bytes_serialize_from_float
.. autocfunction:: serialization.h::z_bytes_serialize_from_double
.. autocfunction:: serialization.h::z_bytes_serialize_from_slice
.. autocfunction:: serialization.h::z_bytes_serialize_from_buf
.. autocfunction:: serialization.h::z_bytes_serialize_from_string
.. autocfunction:: serialization.h::z_bytes_serialize_from_str
.. autocfunction:: serialization.h::ze_deserializer_deserialize_int8
.. autocfunction:: serialization.h::ze_deserializer_deserialize_int16
.. autocfunction:: serialization.h::ze_deserializer_deserialize_int32
.. autocfunction:: serialization.h::ze_deserializer_deserialize_int64
.. autocfunction:: serialization.h::ze_deserializer_deserialize_uint8
.. autocfunction:: serialization.h::ze_deserializer_deserialize_uint16
.. autocfunction:: serialization.h::ze_deserializer_deserialize_uint32
.. autocfunction:: serialization.h::ze_deserializer_deserialize_uint64
.. autocfunction:: serialization.h::ze_deserializer_deserialize_float
.. autocfunction:: serialization.h::ze_deserializer_deserialize_double
.. autocfunction:: serialization.h::ze_deserializer_deserialize_slice
.. autocfunction:: serialization.h::ze_deserializer_deserialize_string
.. autocfunction:: serialization.h::ze_deserializer_deserialize_sequence_begin
.. autocfunction:: serialization.h::ze_deserializer_deserialize_sequence_end
.. autocfunction:: serialization.h::ze_serializer_serialize_int8
.. autocfunction:: serialization.h::ze_serializer_serialize_int16
.. autocfunction:: serialization.h::ze_serializer_serialize_int32
.. autocfunction:: serialization.h::ze_serializer_serialize_int64
.. autocfunction:: serialization.h::ze_serializer_serialize_uint8
.. autocfunction:: serialization.h::ze_serializer_serialize_uint16
.. autocfunction:: serialization.h::ze_serializer_serialize_uint32
.. autocfunction:: serialization.h::ze_serializer_serialize_uint64
.. autocfunction:: serialization.h::ze_serializer_serialize_float
.. autocfunction:: serialization.h::ze_serializer_serialize_double
.. autocfunction:: serialization.h::ze_serializer_serialize_slice
.. autocfunction:: serialization.h::ze_serializer_serialize_buf
.. autocfunction:: serialization.h::ze_serializer_serialize_string
.. autocfunction:: serialization.h::ze_serializer_serialize_str
.. autocfunction:: serialization.h::ze_serializer_serialize_sequence_begin
.. autocfunction:: serialization.h::ze_serializer_serialize_sequence_end
.. autocfunction:: serialization.h::ze_deserialize_into_int8
.. autocfunction:: serialization.h::ze_deserialize_into_int16
.. autocfunction:: serialization.h::ze_deserialize_into_int32
.. autocfunction:: serialization.h::ze_deserialize_into_int64
.. autocfunction:: serialization.h::ze_deserialize_into_uint8
.. autocfunction:: serialization.h::ze_deserialize_into_uint16
.. autocfunction:: serialization.h::ze_deserialize_into_uint32
.. autocfunction:: serialization.h::ze_deserialize_into_uint64
.. autocfunction:: serialization.h::ze_deserialize_into_float
.. autocfunction:: serialization.h::ze_deserialize_into_double
.. autocfunction:: serialization.h::ze_deserialize_into_slice
.. autocfunction:: serialization.h::ze_deserialize_into_string
.. autocfunction:: serialization.h::ze_serialize_from_int8
.. autocfunction:: serialization.h::ze_serialize_from_int16
.. autocfunction:: serialization.h::ze_serialize_from_int32
.. autocfunction:: serialization.h::ze_serialize_from_int64
.. autocfunction:: serialization.h::ze_serialize_from_uint8
.. autocfunction:: serialization.h::ze_serialize_from_uint16
.. autocfunction:: serialization.h::ze_serialize_from_uint32
.. autocfunction:: serialization.h::ze_serialize_from_uint64
.. autocfunction:: serialization.h::ze_serialize_from_float
.. autocfunction:: serialization.h::ze_serialize_from_double
.. autocfunction:: serialization.h::ze_serialize_from_slice
.. autocfunction:: serialization.h::ze_serialize_from_buf
.. autocfunction:: serialization.h::ze_serialize_from_string
.. autocfunction:: serialization.h::ze_serialize_from_str
.. autocfunction:: primitives.h::z_bytes_from_slice
.. autocfunction:: primitives.h::z_bytes_copy_from_slice
.. autocfunction:: primitives.h::z_bytes_from_buf
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ affect the owned object. However, passing the structure to a function transfers
z_publisher_put_options_default(&options);
int64_t metadata = 42;
z_owned_bytes_t attachment;
z_bytes_serialize_from_int64(&attachment, metadata);
ze_serialize_from_int64(&attachment, metadata);
options.attachment = z_move(attachment); // the data itself is still in the `attachment`
z_owned_bytes_t payload;
Expand Down
87 changes: 44 additions & 43 deletions examples/unix/c11/z_bytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef struct kv_pair_t {
static void print_slice_data(z_view_slice_t *slice);

int main(void) {
// wrapping raw data into z_bytes_t
// Wrapping raw data into z_bytes_t
z_owned_bytes_t payload;
{
const uint8_t input_bytes[] = {1, 2, 3, 4};
Expand All @@ -49,7 +49,7 @@ int main(void) {
z_drop(z_move(payload));
z_drop(z_move(output_bytes));

// same can be done for const char*
// The same can be done for const char*
const char *input_str = "test";
z_owned_string_t output_string;
z_bytes_copy_from_str(&payload, input_str);
Expand All @@ -64,8 +64,8 @@ int main(void) {
// Arithmetic types: uint8, uint16, uint32, uint64, int8, int16, int32, int64, float, double
uint32_t input_u32 = 1234;
uint32_t output_u32 = 0;
z_bytes_serialize_from_uint32(&payload, input_u32);
z_bytes_deserialize_into_uint32(z_loan(payload), &output_u32);
ze_serialize_from_uint32(&payload, input_u32);
ze_deserialize_into_uint32(z_loan(payload), &output_u32);
assert(input_u32 == output_u32);
z_drop(z_move(payload));
// Corresponding encoding to be used in operations options like `z_put()`, `z_get()`, etc.
Expand All @@ -86,26 +86,26 @@ int main(void) {
z_drop(z_move(payload));
}

// Using writer/reader for serializing composite types
// Using serializer/deserializer for composite types
{
// A sequence of primitive types
int32_t input_vec[] = {1, 2, 3, 4};
int32_t output_vec[4] = {0};
z_bytes_writer_t writer = z_bytes_get_writer(z_loan_mut(payload));
z_bytes_writer_serialize_sequence_begin(&writer, 4);
ze_serializer_t serializer = ze_serializer(z_loan_mut(payload));
ze_serializer_serialize_sequence_begin(&serializer, 4);
for (size_t i = 0; i < 4; ++i) {
z_bytes_writer_serialize_int32(&writer, input_vec[i]);
ze_serializer_serialize_int32(&serializer, input_vec[i]);
}
z_bytes_writer_serialize_sequence_end(&writer);
ze_serializer_serialize_sequence_end(&serializer);

z_bytes_reader_t reader = z_bytes_get_reader(z_loan(payload));
ze_deserializer_t deserializer = ze_deserializer(z_loan(payload));
size_t num_elements = 0;
z_bytes_reader_deserialize_sequence_begin(&reader, &num_elements);
ze_deserializer_deserialize_sequence_begin(&deserializer, &num_elements);
assert(num_elements == 4);
for (size_t i = 0; i < num_elements; ++i) {
z_bytes_reader_deserialize_int32(&reader, &output_vec[i]);
ze_deserializer_deserialize_int32(&deserializer, &output_vec[i]);
}
z_bytes_reader_deserialize_sequence_end(&reader);
ze_deserializer_deserialize_sequence_end(&deserializer);

for (size_t i = 0; i < 4; ++i) {
assert(input_vec[i] == output_vec[i]);
Expand All @@ -121,23 +121,24 @@ int main(void) {
kvs_input[1].key = 1;
z_string_from_str(&kvs_input[1].value, "def", NULL, NULL);

z_bytes_writer_t writer = z_bytes_get_writer(z_loan_mut(payload));
z_bytes_writer_serialize_sequence_begin(&writer, 2);
ze_serializer_t serializer = ze_serializer(z_loan_mut(payload));
ze_serializer_serialize_sequence_begin(&serializer, 2);
for (size_t i = 0; i < 2; ++i) {
z_bytes_writer_serialize_int32(&writer, kvs_input[i].key);
z_bytes_writer_serialize_string(&writer, z_loan(kvs_input[i].value));
ze_serializer_serialize_int32(&serializer, kvs_input[i].key);
ze_serializer_serialize_string(&serializer, z_loan(kvs_input[i].value));
}
z_bytes_writer_serialize_sequence_end(&writer);
ze_serializer_serialize_sequence_end(&serializer);

z_bytes_reader_t reader = z_bytes_get_reader(z_loan(payload));
ze_deserializer_t deserializer = ze_deserializer(z_loan(payload));
size_t num_elements = 0;
z_bytes_reader_deserialize_sequence_begin(&reader, &num_elements);
ze_deserializer_deserialize_sequence_begin(&deserializer, &num_elements);
assert(num_elements == 2);
kv_pair_t kvs_output[2];
for (size_t i = 0; i < num_elements; ++i) {
z_bytes_reader_deserialize_int32(&reader, &kvs_output[i].key);
z_bytes_reader_deserialize_string(&reader, &kvs_output[i].value);
ze_deserializer_deserialize_int32(&deserializer, &kvs_output[i].key);
ze_deserializer_deserialize_string(&deserializer, &kvs_output[i].value);
}
ze_deserializer_deserialize_sequence_end(&deserializer);

for (size_t i = 0; i < 2; ++i) {
assert(kvs_input[i].key == kvs_output[i].key);
Expand All @@ -150,44 +151,44 @@ int main(void) {
}

{
// custom struct/tuple serializaiton
// Custom struct/tuple serializaiton
custom_struct_t cs = (custom_struct_t){.f = 1.0f, .u = {{1, 2, 3}, {4, 5, 6}}, .c = "test"};

z_bytes_writer_t writer = z_bytes_get_writer(z_loan_mut(payload));
z_bytes_writer_serialize_float(&writer, cs.f);
z_bytes_writer_serialize_sequence_begin(&writer, 2);
ze_serializer_t serializer = ze_serializer(z_loan_mut(payload));
ze_serializer_serialize_float(&serializer, cs.f);
ze_serializer_serialize_sequence_begin(&serializer, 2);
for (size_t i = 0; i < 2; ++i) {
z_bytes_writer_serialize_sequence_begin(&writer, 3);
ze_serializer_serialize_sequence_begin(&serializer, 3);
for (size_t j = 0; j < 3; ++j) {
z_bytes_writer_serialize_uint64(&writer, cs.u[i][j]);
ze_serializer_serialize_uint64(&serializer, cs.u[i][j]);
}
z_bytes_writer_serialize_sequence_end(&writer);
ze_serializer_serialize_sequence_end(&serializer);
}
z_bytes_writer_serialize_sequence_end(&writer);
z_bytes_writer_serialize_str(&writer, cs.c);
ze_serializer_serialize_sequence_end(&serializer);
ze_serializer_serialize_str(&serializer, cs.c);

float f = 0.0f;
uint64_t u = 0;
z_owned_string_t c;

z_bytes_reader_t reader = z_bytes_get_reader(z_loan(payload));
z_bytes_reader_deserialize_float(&reader, &f);
ze_deserializer_t deserializer = ze_deserializer(z_loan(payload));
ze_deserializer_deserialize_float(&deserializer, &f);
assert(f == cs.f);
size_t num_elements0 = 0;
z_bytes_reader_deserialize_sequence_begin(&reader, &num_elements0);
ze_deserializer_deserialize_sequence_begin(&deserializer, &num_elements0);
assert(num_elements0 == 2);
for (size_t i = 0; i < 2; ++i) {
size_t num_elements1 = 0;
z_bytes_reader_deserialize_sequence_begin(&reader, &num_elements1);
ze_deserializer_deserialize_sequence_begin(&deserializer, &num_elements1);
assert(num_elements1 == 3);
for (size_t j = 0; j < 3; ++j) {
z_bytes_reader_deserialize_uint64(&reader, &u);
ze_deserializer_deserialize_uint64(&deserializer, &u);
assert(u == cs.u[i][j]);
}
z_bytes_reader_deserialize_sequence_end(&reader);
ze_deserializer_deserialize_sequence_end(&deserializer);
}
z_bytes_reader_deserialize_sequence_end(&reader);
z_bytes_reader_deserialize_string(&reader, &c);
ze_deserializer_deserialize_sequence_end(&deserializer);
ze_deserializer_deserialize_string(&deserializer, &c);
assert(strncmp(cs.c, z_string_data(z_loan(c)), z_string_len(z_loan(c))) == 0);

z_drop(z_move(c));
Expand All @@ -198,12 +199,12 @@ int main(void) {
{
/// fill z_bytes with some data
float input_vec[] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f};
z_bytes_writer_t writer = z_bytes_get_writer(z_loan_mut(payload));
z_bytes_writer_serialize_sequence_begin(&writer, 5);
ze_serializer_t serializer = ze_serializer(z_loan_mut(payload));
ze_serializer_serialize_sequence_begin(&serializer, 5);
for (size_t i = 0; i < 5; ++i) {
z_bytes_writer_serialize_float(&writer, input_vec[i]);
ze_serializer_serialize_float(&serializer, input_vec[i]);
}
z_bytes_writer_serialize_sequence_end(&writer);
ze_serializer_serialize_sequence_end(&serializer);

z_bytes_slice_iterator_t slice_iter = z_bytes_get_slice_iterator(z_bytes_loan(&payload));
z_view_slice_t curr_slice;
Expand Down
20 changes: 10 additions & 10 deletions examples/unix/c11/z_get_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ void reply_handler(z_loaned_reply_t *reply, void *ctx) {
if (attachment == NULL) {
return;
}
z_bytes_reader_t reader = z_bytes_get_reader(attachment);
ze_deserializer_t deserializer = ze_deserializer(attachment);
size_t attachment_len;
z_bytes_reader_deserialize_sequence_begin(&reader, &attachment_len);
ze_deserializer_deserialize_sequence_begin(&deserializer, &attachment_len);
kv_pair_t *kvp = (kv_pair_t *)malloc(sizeof(kv_pair_t) * attachment_len);
for (size_t i = 0; i < attachment_len; ++i) {
z_bytes_reader_deserialize_string(&reader, &kvp[i].key);
z_bytes_reader_deserialize_string(&reader, &kvp[i].value);
ze_deserializer_deserialize_string(&deserializer, &kvp[i].key);
ze_deserializer_deserialize_string(&deserializer, &kvp[i].value);
}
z_bytes_reader_deserialize_sequence_end(&reader);
ze_deserializer_deserialize_sequence_end(&deserializer);
if (attachment_len > 0) {
print_attachment(kvp, attachment_len);
}
Expand Down Expand Up @@ -178,13 +178,13 @@ int main(int argc, char **argv) {
z_string_from_str(&kvs[0].value, "test_value", NULL, NULL);
z_owned_bytes_t attachment;
z_bytes_empty(&attachment);
z_bytes_writer_t writer = z_bytes_get_writer(z_loan_mut(attachment));
z_bytes_writer_serialize_sequence_begin(&writer, 2);
ze_serializer_t serializer = ze_serializer(z_loan_mut(attachment));
ze_serializer_serialize_sequence_begin(&serializer, 2);
for (size_t i = 0; i < 1; ++i) {
z_bytes_writer_serialize_string(&writer, z_loan(kvs[i].key));
z_bytes_writer_serialize_string(&writer, z_loan(kvs[i].value));
ze_serializer_serialize_string(&serializer, z_loan(kvs[i].key));
ze_serializer_serialize_string(&serializer, z_loan(kvs[i].value));
}
z_bytes_writer_serialize_sequence_end(&writer);
ze_serializer_serialize_sequence_end(&serializer);
drop_attachment(kvs, 1);
opts.attachment = z_move(attachment);

Expand Down
10 changes: 5 additions & 5 deletions examples/unix/c11/z_pub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ int main(int argc, char **argv) {
// Add attachment value
sprintf(buf_ind, "%d", idx);
kvs[1] = (kv_pair_t){.key = "index", .value = buf_ind};
z_bytes_writer_t writer = z_bytes_get_writer(z_loan_mut(attachment));
z_bytes_writer_serialize_sequence_begin(&writer, 2);
ze_serializer_t serializer = ze_serializer(z_loan_mut(attachment));
ze_serializer_serialize_sequence_begin(&serializer, 2);
for (size_t i = 0; i < 2; ++i) {
z_bytes_writer_serialize_str(&writer, kvs[i].key);
z_bytes_writer_serialize_str(&writer, kvs[i].value);
ze_serializer_serialize_str(&serializer, kvs[i].key);
ze_serializer_serialize_str(&serializer, kvs[i].value);
}
z_bytes_writer_serialize_sequence_end(&writer);
ze_serializer_serialize_sequence_end(&serializer);
options.attachment = z_move(attachment);

// Add encoding value
Expand Down
Loading

0 comments on commit 6147932

Please sign in to comment.