Skip to content

Commit

Permalink
Implement dumping of HEP-1 Value Annotations
Browse files Browse the repository at this point in the history
Adds support into hipack_writer_t to dump annotations to the generated
output.
  • Loading branch information
aperezdc committed Dec 9, 2015
1 parent df76bea commit 5b17209
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions hipack-writer.c
Expand Up @@ -222,23 +222,30 @@ write_keyval (hipack_writer_t *writer,
CHECK_IO (writechar (writer, key->data[i]));
}

switch (value->type) {
case HIPACK_INTEGER:
case HIPACK_FLOAT:
case HIPACK_BOOL:
case HIPACK_STRING:
if (value->annot) {
if (writer->indent == HIPACK_WRITER_COMPACT) {
CHECK_IO (writechar (writer, ':'));
break;
case HIPACK_DICT:
case HIPACK_LIST:
/* No colon. */
break;
default:
assert (false);
}

if (writer->indent != HIPACK_WRITER_COMPACT) {
CHECK_IO (writechar (writer, ' '));
} else {
CHECK_IO (writechar (writer, ' '));
}
} else {
switch (value->type) {
case HIPACK_INTEGER:
case HIPACK_FLOAT:
case HIPACK_BOOL:
case HIPACK_STRING:
CHECK_IO (writechar (writer, ':'));
break;
case HIPACK_DICT:
case HIPACK_LIST:
/* No colon. */
break;
default:
assert (false);
}
if (writer->indent != HIPACK_WRITER_COMPACT) {
CHECK_IO (writechar (writer, ' '));
}
}

CHECK_IO (hipack_write_value (writer, value));
Expand Down Expand Up @@ -315,6 +322,18 @@ hipack_write_value (hipack_writer_t *writer,
assert (writer);
assert (value);

if (value->annot) {
const hipack_string_t *key;
hipack_value_t *dummy_value;
HIPACK_DICT_FOREACH (value->annot, key, dummy_value) {
CHECK_IO (writechar (writer, ':'));
for (uint32_t i = 0; i < key->size; i++) {
CHECK_IO (writechar (writer, key->data[i]));
}
}
CHECK_IO (writechar (writer, ' '));
}

switch (value->type) {
case HIPACK_INTEGER:
return hipack_write_integer (writer, value->v_integer);
Expand Down

0 comments on commit 5b17209

Please sign in to comment.