Skip to content

Commit

Permalink
Add msgpack obj init for complex types
Browse files Browse the repository at this point in the history
Signed-off-by: Athish Pranav D <[email protected]>
  • Loading branch information
Athishpranav2003 committed Aug 13, 2024
1 parent eba6304 commit c1cb968
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/objectc.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,46 @@ int msgpack_pack_object(msgpack_packer* pk, msgpack_object d)
}
}

int msgpack_object_init(msgpack_object* d, void *data, size_t size, int type)
{
d->type = type;
switch (type) {
case MSGPACK_OBJECT_STR:
{
d->via.str.ptr = (char *)data;
d->via.str.size = size;
break;
}
case MSGPACK_OBJECT_BIN:
{
d->type = type;
d->via.bin.ptr = (char *)data;
d->via.bin.size = size;
break;
}
case MSGPACK_OBJECT_ARRAY:
{
d->via.array.ptr = (msgpack_object *)data;
d->via.array.size = size;
break;
}
case MSGPACK_OBJECT_MAP:
{
d->via.map.ptr = (msgpack_object_kv *) data;
d->via.map.size = size;
break;
}
default:
{
// Other types are not supported and need to be initialized manually.
d->type = MSGPACK_OBJECT_NIL;
return -1;
}
}
return 0;

}

#if !defined(_KERNEL_MODE)

static void msgpack_object_bin_print(FILE* out, const char *ptr, size_t size)
Expand Down

0 comments on commit c1cb968

Please sign in to comment.