Skip to content

Commit 26ce766

Browse files
committed
val: fully implement unpacking
Until now, val_unpack was just a stub that always returned -ENOTSUP. With the recent addition of the cbor unpacking API, we can finally wire it up. Signed-off-by: Josef 'Jeff' Sipek <[email protected]>
1 parent 0815cf2 commit 26ce766

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

val_impl_packing.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030

3131
struct valops {
3232
int (*pack)(struct buffer *buffer, struct val *val);
33+
struct val *(*unpack)(struct buffer *buffer);
3334
};
3435

3536
static const struct valops valops_cbor = {
3637
.pack = cbor_pack_val,
38+
.unpack = cbor_unpack_val,
3739
};
3840

3941
static const struct valops valops_json = {

val_unpack.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2018 Josef 'Jeff' Sipek <[email protected]>
2+
* Copyright (c) 2017-2019 Josef 'Jeff' Sipek <[email protected]>
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -28,13 +28,13 @@
2828
struct val *val_unpack(const void *ptr, size_t len, enum val_format format)
2929
{
3030
const struct valops *ops;
31-
int ret;
31+
struct buffer buffer;
3232

3333
ops = select_ops(format);
34-
if (!ops)
34+
if (!ops || !ops->unpack)
3535
return ERR_PTR(-ENOTSUP);
3636

37-
ret = -ENOTSUP; /* FIXME */
37+
buffer_init_static(&buffer, ptr, len, false);
3838

39-
return ERR_PTR(ret);
39+
return ops->unpack(&buffer);
4040
}

0 commit comments

Comments
 (0)