summaryrefslogtreecommitdiff
path: root/json.c
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2019-05-17 13:26:09 -0700
committerGary E. Miller <gem@rellim.com>2019-05-17 13:26:32 -0700
commitbe2cabf020cdadce60086ab0ad526254492bae86 (patch)
treeb3a2bc32fa40fc6c6d949c641de4bfeed8e1be89 /json.c
parent031cb48dc3adfc2b239df98f0bbe99da15c3959c (diff)
downloadgpsd-be2cabf020cdadce60086ab0ad526254492bae86.tar.gz
json.c: Add t_byte and t_ubyte decodes.
No changes to existing decodes.
Diffstat (limited to 'json.c')
-rw-r--r--json.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/json.c b/json.c
index b797b1a2..ce7f221d 100644
--- a/json.c
+++ b/json.c
@@ -117,6 +117,12 @@ static char *json_target_address(const struct json_attr_t *cursor,
if (parent == NULL || parent->element_type != t_structobject) {
/* ordinary case - use the address in the cursor structure */
switch (cursor->type) {
+ case t_byte:
+ targetaddr = (char *)&cursor->addr.byte[offset];
+ break;
+ case t_ubyte:
+ targetaddr = (char *)&cursor->addr.ubyte[offset];
+ break;
case t_ignore:
targetaddr = NULL;
break;
@@ -195,6 +201,12 @@ static int json_internal_read_object(const char *cp,
lptr = json_target_address(cursor, parent, offset);
if (lptr != NULL)
switch (cursor->type) {
+ case t_byte:
+ lptr[0] = cursor->dflt.byte;
+ break;
+ case t_ubyte:
+ lptr[0] = cursor->dflt.ubyte;
+ break;
case t_integer:
memcpy(lptr, &cursor->dflt.integer, sizeof(int));
break;
@@ -482,6 +494,18 @@ static int json_internal_read_object(const char *cp,
lptr = json_target_address(cursor, parent, offset);
if (lptr != NULL)
switch (cursor->type) {
+ case t_byte:
+ {
+ int tmp = atoi(valbuf);
+ lptr[0] = (char)tmp;
+ }
+ break;
+ case t_ubyte:
+ {
+ int tmp = atoi(valbuf);
+ lptr[0] = (unsigned char)tmp;
+ }
+ break;
case t_integer:
{
int tmp = atoi(valbuf);
@@ -665,6 +689,21 @@ int json_read_array(const char *cp, const struct json_array_t *arr,
else
cp = ep;
break;
+ case t_byte:
+ arr->arr.bytes.store[offset] = (char)strtol(cp, &ep, 0);
+ if (ep == cp)
+ return JSON_ERR_BADNUM;
+ else
+ cp = ep;
+ break;
+ case t_ubyte:
+ arr->arr.ubytes.store[offset] = (unsigned char)strtoul(cp,
+ &ep, 0);
+ if (ep == cp)
+ return JSON_ERR_BADNUM;
+ else
+ cp = ep;
+ break;
case t_short:
arr->arr.shorts.store[offset] = (short)strtol(cp, &ep, 0);
if (ep == cp)