NordicSemiconductor / IOS-nRF-Connect-Device-Manager

A mobile management library for devices supporting nRF Connect Device Manager.
https://www.nordicsemi.com/Software-and-tools/Software/nRF-Connect-SDK
Apache License 2.0
97 stars 41 forks source link

When parsing more complicated CBOR structure some elements disappears #13

Closed ramunasjurgilas closed 2 years ago

ramunasjurgilas commented 2 years ago

I have CBOR structure

As text:

{"files": [{"name": "/lfs/hr/1.hr", "time": 806548, "id": 1, "size": 5, "checksum": 758453377},{"name": "/lfs/hr/2.hr", "time": 806548, "id": 2, "size": 5, "checksum": 758453377}], "status":1}

As HEX:

A26566696C65736E616D656C2F6C66732F68722F312E68774696D651A000C4E9473697A65636865636B73756D1AD3514816E616D656C2F6C66732F68722F322E68774696D651A000C4E9473697A65636865636B73756D1A2D35148101

When adding break point at file McuMgrResponse.swift:129

payloadData contains correct data:

(lldb) po String(decoding: payloadData!, as: UTF8.self)
"�dnamel/lfs/hr/1.hrdtime\u{1A}\0\u{0C}N�bid\u{01}dsize\u{05}hchecksum\u{1A}-5\u{14}��dnamel/lfs/hr/2.hrdtime\u{1A}\0\u{0C}N�bid\u{02}dsize\u{05}hchecksum\u{1A}-5\u{14}�fstatus\u{01}"

Unfortunately parsed payload do not contains all data. It is missing /lfs/hr/2.hr and some other fields.

(lldb) po payload
▿ Optional<CBOR>
  ▿ some : {"checksum" : 758453377, "id" : 1, "name" : "/lfs/hr/1.hr", "size" : 5, "time" : 806548}
    ▿ map : 5 elements
      ▿ 0 : 2 elements
        ▿ key : "checksum"
          - utf8String : "checksum"
        ▿ value : 758453377
          - unsignedInt : 758453377
      ▿ 1 : 2 elements
        ▿ key : "id"
          - utf8String : "id"
        ▿ value : 1
          - unsignedInt : 1
      ▿ 2 : 2 elements
        ▿ key : "name"
          - utf8String : "name"
        ▿ value : "/lfs/hr/1.hr"
          - utf8String : "/lfs/hr/1.hr"
      ▿ 3 : 2 elements
        ▿ key : "size"
          - utf8String : "size"
        ▿ value : 5
          - unsignedInt : 5
      ▿ 4 : 2 elements
        ▿ key : "time"
          - utf8String : "time"
        ▿ value : 806548
          - unsignedInt : 806548

Is CBOR not support more complicated parsing structures?

ramunasjurgilas commented 2 years ago

Here was a problem on my side. All good with CBOR.