Skip to content

Commit

Permalink
fix: print memory as hex
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Sep 19, 2024
1 parent b6ae5c3 commit 6f3a235
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions examples/unix/c11/z_bytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static bool hashmap_iter(z_owned_bytes_t *kv_pair, void *context);
static bool iter_body(z_owned_bytes_t *b, void *context);
static void parse_hashmap(kv_pairs_rx_t *kvp, const z_loaned_bytes_t *hashmap);
static void drop_hashmap(kv_pairs_rx_t *kvp);
static void print_slice_data(z_view_slice_t *slice);

int main(void) {
// z_owned_encoding_t encoding;
Expand Down Expand Up @@ -140,9 +141,9 @@ int main(void) {
z_bytes_slice_iterator_t slice_iter = z_bytes_get_slice_iterator(z_bytes_loan(&payload));
z_view_slice_t curr_slice;
while (z_bytes_slice_iterator_next(&slice_iter, &curr_slice)) {
printf("slice len: %d, slice data: '%.*s'\n", (int)z_slice_len(z_view_slice_loan(&curr_slice)),
(int)z_slice_len(z_view_slice_loan(&curr_slice)),
(const char *)z_slice_data(z_view_slice_loan(&curr_slice)));
printf("slice len: %d, slice data: '", (int)z_slice_len(z_view_slice_loan(&curr_slice)));
print_slice_data(&curr_slice);
printf("'\n");
}
z_drop(z_move(payload));

Expand Down Expand Up @@ -196,3 +197,9 @@ static void drop_hashmap(kv_pairs_rx_t *kvp) {
}
z_free(kvp->data);
}

static void print_slice_data(z_view_slice_t *slice) {
for (size_t i = 0; i < z_slice_len(z_view_slice_loan(slice)); i++) {
printf("0x%02x ", z_slice_data(z_view_slice_loan(slice))[i]);
}
}

0 comments on commit 6f3a235

Please sign in to comment.