You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by Aditya Xavier <ad...@me.com.INVALID> on 2018/08/10 07:06:51 UTC

CBOR Decoding problem

Hello !


Require some guidance on how to write a CBOR parsing implementation for the following structure.

{a:[1,2,3,4], b:[ {c:[1,2,3,4,5]}, {c:[1,2,3,4,5]}]}

I tried the following implementation.
———————————————————————————————————————————————————————

uint64_t a[5];
Int a_count = 0;

struct c_object{
	int c[6];
}c_arr_objs[5];
int c_obj_count = 0;

struct cbor_attr_t c_attrs[] = {
    {
        .attribute = “c",
        .type = CborAttrObjectType,
        CBORATTR_STRUCT_OBJECT(struct c_object, c),
        .dflt.integer = 0
    },
    {
        .attribute = NULL
    }
};


struct cbor_attr_t root_attrs[] = {
    {
        .attribute = “a",
        .type = CborAttrArrayType,
        .addr.array.element_type = CborAttrUnsignedIntegerType,
        .addr.array.arr.uintegers.store = a,
        .addr.array.count = &a_count,
        .addr.array.maxlen = sizeof(a) / sizeof(a[0]),
        .nodefault = true
    },
    {
        .attribute = “b",
        .type = CborAttrArrayType,
        CBORATTR_STRUCT_ARRAY(c_arr_objs, c_attrs, &c_obj_count),
        .nodefault = true
    },
    {
        .attribute = NULL
    }
};

———————————————————————————————————————————————————————


I assumed this to work as I have been using the same albeit without ‘c’ being a int Array. It works when I use ‘c’ as a Int etc, but not as a int Array, 

The example :- https://github.com/apache/mynewt-core/blob/master/encoding/cborattr/test/src/testcases/cborattr_decode_object_array.c <https://github.com/apache/mynewt-core/blob/master/encoding/cborattr/test/src/testcases/cborattr_decode_object_array.c>

Has a similar implementation for Text String instead of Int Array.

Thanks,
Aditya Xavier.




Re: CBOR Decoding problem

Posted by marko kiiskila <ma...@runtime.io>.
It is possible it might not work right off the bat. At least, I have not built such objects myself.
We do accept contributions ;)

You can also build code using the tinycbor decoder. This is what cborattr itself uses, if you
don’t have time to augment cborattr.

> On Aug 13, 2018, at 10:28 AM, Aditya Xavier <ad...@me.com.INVALID> wrote:
> 
> Thanks for replying !
> 
> Yeah, but If I do that, I won’t have an Array of Arrays right ?
> 
> i.e. I want to have {a:[1,2,3,4], b:[ {c:[1,2,3,4,5]}, {c:[1,2,3,4,5]}]} structure..
> 
> Which means, I need multiple instances of C object. Hence the struct c_object creation.. If I make CborAttrArrayType
> 
> Am not sure that will work.
> 
> Please correct me if am wrong.
> 
> Thanks,
> Aditya Xavier.
> 
> 
> 
>> On 13-Aug-2018, at 12:53 PM, marko kiiskila <ma...@runtime.io> wrote:
>> 
>> “c" looks like an int array instead of an object. Hope that helps
>> 
>>> On Aug 10, 2018, at 10:06 AM, Aditya Xavier <ad...@me.com.INVALID> wrote:
>>> 
>>> Hello !
>>> 
>>> 
>>> Require some guidance on how to write a CBOR parsing implementation for the following structure.
>>> 
>>> {a:[1,2,3,4], b:[ {c:[1,2,3,4,5]}, {c:[1,2,3,4,5]}]}
>>> 
>>> I tried the following implementation.
>>> ———————————————————————————————————————————————————————
>>> 
>>> uint64_t a[5];
>>> Int a_count = 0;
>>> 
>>> struct c_object{
>>> 	int c[6];
>>> }c_arr_objs[5];
>>> int c_obj_count = 0;
>>> 
>>> struct cbor_attr_t c_attrs[] = {
>>>  {
>>>      .attribute = “c",
>>>      .type = CborAttrObjectType,
>>>      CBORATTR_STRUCT_OBJECT(struct c_object, c),
>>>      .dflt.integer = 0
>>>  },
>>>  {
>>>      .attribute = NULL
>>>  }
>>> };
>>> 
>>> 
>>> struct cbor_attr_t root_attrs[] = {
>>>  {
>>>      .attribute = “a",
>>>      .type = CborAttrArrayType,
>>>      .addr.array.element_type = CborAttrUnsignedIntegerType,
>>>      .addr.array.arr.uintegers.store = a,
>>>      .addr.array.count = &a_count,
>>>      .addr.array.maxlen = sizeof(a) / sizeof(a[0]),
>>>      .nodefault = true
>>>  },
>>>  {
>>>      .attribute = “b",
>>>      .type = CborAttrArrayType,
>>>      CBORATTR_STRUCT_ARRAY(c_arr_objs, c_attrs, &c_obj_count),
>>>      .nodefault = true
>>>  },
>>>  {
>>>      .attribute = NULL
>>>  }
>>> };
>>> 
>>> ———————————————————————————————————————————————————————
>>> 
>>> 
>>> I assumed this to work as I have been using the same albeit without ‘c’ being a int Array. It works when I use ‘c’ as a Int etc, but not as a int Array, 
>>> 
>>> The example :- https://github.com/apache/mynewt-core/blob/master/encoding/cborattr/test/src/testcases/cborattr_decode_object_array.c <https://github.com/apache/mynewt-core/blob/master/encoding/cborattr/test/src/testcases/cborattr_decode_object_array.c>
>>> 
>>> Has a similar implementation for Text String instead of Int Array.
>>> 
>>> Thanks,
>>> Aditya Xavier.
>>> 
>>> 
>>> 
>> 
> 


Re: CBOR Decoding problem

Posted by Aditya Xavier <ad...@me.com.INVALID>.
Thanks for replying !

Yeah, but If I do that, I won’t have an Array of Arrays right ?

i.e. I want to have {a:[1,2,3,4], b:[ {c:[1,2,3,4,5]}, {c:[1,2,3,4,5]}]} structure..

Which means, I need multiple instances of C object. Hence the struct c_object creation.. If I make CborAttrArrayType

Am not sure that will work.

Please correct me if am wrong.

Thanks,
Aditya Xavier.



> On 13-Aug-2018, at 12:53 PM, marko kiiskila <ma...@runtime.io> wrote:
> 
> “c" looks like an int array instead of an object. Hope that helps
> 
>> On Aug 10, 2018, at 10:06 AM, Aditya Xavier <ad...@me.com.INVALID> wrote:
>> 
>> Hello !
>> 
>> 
>> Require some guidance on how to write a CBOR parsing implementation for the following structure.
>> 
>> {a:[1,2,3,4], b:[ {c:[1,2,3,4,5]}, {c:[1,2,3,4,5]}]}
>> 
>> I tried the following implementation.
>> ———————————————————————————————————————————————————————
>> 
>> uint64_t a[5];
>> Int a_count = 0;
>> 
>> struct c_object{
>> 	int c[6];
>> }c_arr_objs[5];
>> int c_obj_count = 0;
>> 
>> struct cbor_attr_t c_attrs[] = {
>>   {
>>       .attribute = “c",
>>       .type = CborAttrObjectType,
>>       CBORATTR_STRUCT_OBJECT(struct c_object, c),
>>       .dflt.integer = 0
>>   },
>>   {
>>       .attribute = NULL
>>   }
>> };
>> 
>> 
>> struct cbor_attr_t root_attrs[] = {
>>   {
>>       .attribute = “a",
>>       .type = CborAttrArrayType,
>>       .addr.array.element_type = CborAttrUnsignedIntegerType,
>>       .addr.array.arr.uintegers.store = a,
>>       .addr.array.count = &a_count,
>>       .addr.array.maxlen = sizeof(a) / sizeof(a[0]),
>>       .nodefault = true
>>   },
>>   {
>>       .attribute = “b",
>>       .type = CborAttrArrayType,
>>       CBORATTR_STRUCT_ARRAY(c_arr_objs, c_attrs, &c_obj_count),
>>       .nodefault = true
>>   },
>>   {
>>       .attribute = NULL
>>   }
>> };
>> 
>> ———————————————————————————————————————————————————————
>> 
>> 
>> I assumed this to work as I have been using the same albeit without ‘c’ being a int Array. It works when I use ‘c’ as a Int etc, but not as a int Array, 
>> 
>> The example :- https://github.com/apache/mynewt-core/blob/master/encoding/cborattr/test/src/testcases/cborattr_decode_object_array.c <https://github.com/apache/mynewt-core/blob/master/encoding/cborattr/test/src/testcases/cborattr_decode_object_array.c>
>> 
>> Has a similar implementation for Text String instead of Int Array.
>> 
>> Thanks,
>> Aditya Xavier.
>> 
>> 
>> 
> 


Re: CBOR Decoding problem

Posted by marko kiiskila <ma...@runtime.io>.
“c" looks like an int array instead of an object. Hope that helps

> On Aug 10, 2018, at 10:06 AM, Aditya Xavier <ad...@me.com.INVALID> wrote:
> 
> Hello !
> 
> 
> Require some guidance on how to write a CBOR parsing implementation for the following structure.
> 
> {a:[1,2,3,4], b:[ {c:[1,2,3,4,5]}, {c:[1,2,3,4,5]}]}
> 
> I tried the following implementation.
> ———————————————————————————————————————————————————————
> 
> uint64_t a[5];
> Int a_count = 0;
> 
> struct c_object{
> 	int c[6];
> }c_arr_objs[5];
> int c_obj_count = 0;
> 
> struct cbor_attr_t c_attrs[] = {
>    {
>        .attribute = “c",
>        .type = CborAttrObjectType,
>        CBORATTR_STRUCT_OBJECT(struct c_object, c),
>        .dflt.integer = 0
>    },
>    {
>        .attribute = NULL
>    }
> };
> 
> 
> struct cbor_attr_t root_attrs[] = {
>    {
>        .attribute = “a",
>        .type = CborAttrArrayType,
>        .addr.array.element_type = CborAttrUnsignedIntegerType,
>        .addr.array.arr.uintegers.store = a,
>        .addr.array.count = &a_count,
>        .addr.array.maxlen = sizeof(a) / sizeof(a[0]),
>        .nodefault = true
>    },
>    {
>        .attribute = “b",
>        .type = CborAttrArrayType,
>        CBORATTR_STRUCT_ARRAY(c_arr_objs, c_attrs, &c_obj_count),
>        .nodefault = true
>    },
>    {
>        .attribute = NULL
>    }
> };
> 
> ———————————————————————————————————————————————————————
> 
> 
> I assumed this to work as I have been using the same albeit without ‘c’ being a int Array. It works when I use ‘c’ as a Int etc, but not as a int Array, 
> 
> The example :- https://github.com/apache/mynewt-core/blob/master/encoding/cborattr/test/src/testcases/cborattr_decode_object_array.c <https://github.com/apache/mynewt-core/blob/master/encoding/cborattr/test/src/testcases/cborattr_decode_object_array.c>
> 
> Has a similar implementation for Text String instead of Int Array.
> 
> Thanks,
> Aditya Xavier.
> 
> 
> 


Re: CBOR Decoding problem

Posted by Aditya Xavier <ad...@me.com.INVALID>.
Guys any help on this?

How do I implement cbor decoding for such a structure

Sent from my iPhone

> On 10-Aug-2018, at 12:36 PM, Aditya Xavier <ad...@me.com.INVALID> wrote:
> 
> Hello !
> 
> 
> Require some guidance on how to write a CBOR parsing implementation for the following structure.
> 
> {a:[1,2,3,4], b:[ {c:[1,2,3,4,5]}, {c:[1,2,3,4,5]}]}
> 
> I tried the following implementation.
> ———————————————————————————————————————————————————————
> 
> uint64_t a[5];
> Int a_count = 0;
> 
> struct c_object{
>    int c[6];
> }c_arr_objs[5];
> int c_obj_count = 0;
> 
> struct cbor_attr_t c_attrs[] = {
>    {
>        .attribute = “c",
>        .type = CborAttrObjectType,
>        CBORATTR_STRUCT_OBJECT(struct c_object, c),
>        .dflt.integer = 0
>    },
>    {
>        .attribute = NULL
>    }
> };
> 
> 
> struct cbor_attr_t root_attrs[] = {
>    {
>        .attribute = “a",
>        .type = CborAttrArrayType,
>        .addr.array.element_type = CborAttrUnsignedIntegerType,
>        .addr.array.arr.uintegers.store = a,
>        .addr.array.count = &a_count,
>        .addr.array.maxlen = sizeof(a) / sizeof(a[0]),
>        .nodefault = true
>    },
>    {
>        .attribute = “b",
>        .type = CborAttrArrayType,
>        CBORATTR_STRUCT_ARRAY(c_arr_objs, c_attrs, &c_obj_count),
>        .nodefault = true
>    },
>    {
>        .attribute = NULL
>    }
> };
> 
> ———————————————————————————————————————————————————————
> 
> 
> I assumed this to work as I have been using the same albeit without ‘c’ being a int Array. It works when I use ‘c’ as a Int etc, but not as a int Array, 
> 
> The example :- https://github.com/apache/mynewt-core/blob/master/encoding/cborattr/test/src/testcases/cborattr_decode_object_array.c <https://github.com/apache/mynewt-core/blob/master/encoding/cborattr/test/src/testcases/cborattr_decode_object_array.c>
> 
> Has a similar implementation for Text String instead of Int Array.
> 
> Thanks,
> Aditya Xavier.
> 
> 
>