bluejay icon indicating copy to clipboard operation
bluejay copied to clipboard

Crash in the extract function (remove ability to try deserialize unsupported types)

Open akmarinov opened this issue 6 years ago • 3 comments

I'm having an issue where Bluejay crashes in

screenshot 2018-08-21 15 39 07

Here's the call stack:

screenshot 2018-08-21 15 39 15

There's no console output for the crash, just that bad access.

My code is

struct AdvertisingData: Receivable {
    private(set) var partNumber: String
    private(set) var serialNumber: String


    init(bluetoothData: Data) throws {
        let serialNumberData: Data = try bluetoothData.extract(start: 0, length: 6)

    }
}

if I do

let partNumberData: Data = bluetoothData.subdata(in: 0..<0+6)

instead on my own, I'm able to get the sub data and use it to initialize my string to the correct value.

Any idea why you use .withUnsafeBytes { $0.pointee } and why it seems to crash with bad access?

Am I doing something wrong? I want to extract a string from a data that I receive.

akmarinov avatar Aug 21 '18 12:08 akmarinov

Thank you for finding this problem. I've filed an issue #164 with explanations and solutions for moving forward, and sorry we weren't able to catch this earlier in our development and testing.

sakuraehikaru avatar Aug 21 '18 21:08 sakuraehikaru

No worries, love the library!

It’s not just Strings, btw. Trying to extract a Data in this case and it still fails. (Though Strings also fail)

akmarinov avatar Aug 21 '18 21:08 akmarinov

At long last, we're close to having a reasonable solution for this: https://github.com/steamclock/bluejay/pull/195

I've tested the PR and both string and data extraction are now working as expected. Also, see the updated readme in that branch for more examples.

sakuraehikaru avatar Mar 11 '19 21:03 sakuraehikaru