Skip to content

Commit

Permalink
Support vlen sequences of fixed len strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Feb 23, 2024
1 parent 785bc0b commit 9735272
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/rest_vol_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -5032,6 +5032,16 @@ RV_json_values_to_binary_recursive(yajl_val value_entry, hid_t dtype_id, void *v
}
} break;

case(H5T_STRING): {
char *vlen_char = NULL;

if ((vlen_char = YAJL_GET_STRING(value_entry)) == NULL)
FUNC_GOTO_ERROR(H5E_OBJECT, H5E_PARSEERROR, FAIL, "parsed vlen character sequence was NULL");

memcpy((char*) value_buffer, vlen_char, dtype_size);

} break;

case (H5T_COMPOUND): {
/* Recursively parse each member of the compound type */
int nmembers = 0;
Expand Down Expand Up @@ -5153,6 +5163,7 @@ RV_vlen_data_to_json(const void *_in, size_t nelems, hid_t dtype_id, void **out,
ptrdiff_t out_diff = 0;
int bytes_printed = 0;
size_t tgt_out_size = 0;
size_t parent_size;

const char *const leading_string = "{\"value\":";
const char *const closing_string = "]}";
Expand All @@ -5172,6 +5183,9 @@ RV_vlen_data_to_json(const void *_in, size_t nelems, hid_t dtype_id, void **out,

if ((parent_class = H5Tget_class(parent_type)) < 0)
FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get class of parent of vlen dtype");

if ((parent_size = H5Tget_size(parent_type)) == 0)
FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get size of vlen seq base type");

if ((out_string = (char *)calloc(DATASET_VLEN_JSON_BODY_DEFAULT_SIZE, 1)) == NULL)
FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate space for vlen data JSON");
Expand Down Expand Up @@ -5221,23 +5235,36 @@ RV_vlen_data_to_json(const void *_in, size_t nelems, hid_t dtype_id, void **out,
if ((bytes_printed = snprintf(seq_elem_buffer_ptr, MAX_SEQ_ELEM_BUF_SIZE, "%d",
((int *)seq.p)[j])) < 0)
FUNC_GOTO_ERROR(H5E_DATASET, H5E_SYSERRSTR, FAIL, "snprintf error");

seq_elem_buffer_ptr += bytes_printed;
break;
case (H5T_FLOAT):
if ((bytes_printed = snprintf(seq_elem_buffer_ptr, MAX_SEQ_ELEM_BUF_SIZE, "%f",
((float *)seq.p)[j])) < 0)
FUNC_GOTO_ERROR(H5E_DATASET, H5E_SYSERRSTR, FAIL, "snprintf error");
seq_elem_buffer_ptr += bytes_printed;
break;
case (H5T_STRING):
if ((bytes_printed = snprintf(seq_elem_buffer_ptr, MAX_SEQ_ELEM_BUF_SIZE, "%d",
((char *)seq.p)[j])) < 0)
FUNC_GOTO_ERROR(H5E_DATASET, H5E_SYSERRSTR, FAIL, "snprintf error");
if (parent_size + 2 + 1 >= MAX_SEQ_ELEM_BUF_SIZE)
FUNC_GOTO_ERROR(H5E_DATASET, H5E_SYSERRSTR, FAIL, "size of string element in vlen seq exceeded buffer size");

*seq_elem_buffer_ptr = '"';
seq_elem_buffer_ptr += 1;

memcpy(seq_elem_buffer_ptr, ((char*)seq.p) + j * parent_size, parent_size);
bytes_printed = (int) parent_size;
seq_elem_buffer_ptr += parent_size;

*seq_elem_buffer_ptr = '"';
seq_elem_buffer_ptr += 1;
*seq_elem_buffer_ptr = '\0';

break;
default:
FUNC_GOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unsupported vlen parent type");
break;
}

seq_elem_buffer_ptr += bytes_printed;

/* Check if room for comma */
if (bytes_printed + 1 > MAX_SEQ_ELEM_BUF_SIZE)
Expand Down

0 comments on commit 9735272

Please sign in to comment.