shamblett / cbor

A CBOR implementation for Dart
MIT License
36 stars 16 forks source link

Bad state: No element - map tagetSize out of bounds #27

Closed djorgji closed 2 years ago

djorgji commented 2 years ago

Hi,

I am trying to parse the response from an Amazon FreeRTOS ListNetworResp: Example Java impl

Example Payloads:

[log] raw input [169, 97, 119, 2, 97, 115, 0, 97, 114, 113, 84, 114, 117, 101, 66, 108, 117, 101, 32, 83]
[log] STRING ©awasarqTrueBlue S

[log] raw input [169, 97, 119, 2, 97, 115, 0, 97, 114, 110, 84, 114, 117, 101, 66, 108, 117, 101, 32, 71]
[log] STRING ©awasarnTrueBlue G

[log] raw input [169, 97, 119, 2, 97, 115, 0, 97, 114, 103, 67, 70, 71, 45, 50, 46, 52, 97, 98, 70]
[log] STRING ©awasargCFG-2.4abF

Getting:

Bad state: No element
#0      ListQueue.last (dart:collection/queue.dart:636:25)
#1      Stack.pop
package:cbor/src/cbor_stack.dart:33
#2      ItemStack.pop
package:cbor/src/cbor_item_stack.dart:35
#3      DecodeStack._processIterable
package:cbor/src/cbor_decode_stack.dart:121
#4      DecodeStack.build
package:cbor/src/cbor_decode_stack.dart:56
#5      Cbor.getDecodedData
package:cbor/src/cbor.dart:65

Thank you in advance.

shamblett commented 2 years ago

If you go to this site and convert your first example in hex i.e.

A9 61 77 2 61 73 00 61 72 71 54 72 75 65 42 6C 75 65 20 53

You get this reply -

Out of bytes to decode (need at least 7 bytes more).

So it looks as though your CBOR is malformed.

djorgji commented 2 years ago

Hi, thank you for the fast response! I am a total newbie with CBOR.

Is there a way to tweak what I give the Dart Decoder, to allow it to parse the data?

The website you linked above does show the same error (7 bytes more) error for these. Can you help me understand how the CBOR Java Decoder amazon is using in their code is decoding these? Utilized in this class Java impl

2021-11-17 16:27:08.344 3743-3840/software.amazon.freertos.demo D/FRD: ->->-> 
Characteristic changed for: NETWORK_TX with data: a961770261730061726e5472
2021-11-17 16:27:08.346 3743-3840/software.amazon.freertos.demo I/FRD: Handling Network Message type : 2
2021-11-17 16:27:08.350 3743-3840/software.amazon.freertos.demo D/FRD: List network response -> Status: 0 ssid: TrueBlue Guest bssid: 8a:15:04:cb:6e:83 security: 3 hidden: false rssi: -44 connected: false index: -1
2021-11-17 16:27:08.351 3743-3840/software.amazon.freertos.demo D/FRD: ->->-> 
Characteristic changed for: NETWORK_TX with data: a96177026173006172715472
2021-11-17 16:27:08.352 3743-3840/software.amazon.freertos.demo I/FRD: Handling Network Message type : 2
2021-11-17 16:27:08.353 3743-3840/software.amazon.freertos.demo D/FRD: List network response -> Status: 0 ssid: TrueBlue Standard bssid: 8a:15:04:cb:6e:81 security: 6 hidden: false rssi: -45 connected: false index: -1

Thank you.

shamblett commented 2 years ago

I'm not a Java guy so the java code isn't going to help here.

You can't 'tweak' either the CBOR playground or this packages decoder, they will only decode valid CBOR as per the spec.

How do you know the data above is CBOR? Looking at the Amazon Free RTOS docs suggests that only the IOT device defender uses CBOR, the other examples don't seem to.

djorgji commented 2 years ago

I know it is CBOR based on what the existing freertos-ble-demos have, they have both android and iOS examples. I am trying to reimplement them in flutter/dart so I can have the ability stay multi platform beyond just iOS/Android. I am using this plugin for the actual BLE itself.

I am able to use your encoder just fine to send the request to scan for wifi just fine (thank you), however I can not decode back the responses.

Here are the iOS relevant snippets that mention CBOR.

GATT notify which calls the decode function with this model type, which mentions CBOR at the top comment.

djorgji commented 2 years ago

Resolution: So it looks like it is working on iOS side, a961770261730061726e54727565426c75652047756573746162468a1504cb6e836171036166f46170382f6165f4616720 Android seems to relate to: https://github.com/aws/amazon-freertos-ble-android-sdk/issues/2