I'm working on a barcode scanner app (Swift 3+) that uses the new Vision Framework in iOS 11, specifically VNBarcodeObservation
and barcodeDescriptor. The barcodes are Aztec barcodes of format ETF-918.3 and contain binary data, some of which (usually starting at offset 68) is a zlib
stream. I can scan the barcode, get the observation, the CIAztecCodeDescriptor and its errorCorrectedPayload
.
I have picked 3 Examples to illustrate the weird behavior exhibited when errorCorrectedPayload
is compared to the sample data. The sample data decompresses just fine in all 3 cases. The links go to images of the respective barcodes.
- Example 1:
errorCorrectedPayload
zlib does not decompress
- Example 2:
errorCorrectedPayload
zlib does decompress!
- Example 3:
errorCorrectedPayload
contains no zlib header
The 3 samples were optained under the exact same circumstances, scanned by the same code.
My question is: is there a way to consistently get data identical to the samples from the Vision Framework? Is it possible to "transform" the data? And why does Example 2 work at all?!
The bytes I get from the errorCorrectedPayload
(Swift Data
) never match my samples. I just output them like so
if let desc = barcode.barcodeDescriptor as? CIAztecCodeDescriptor {
let rawBytes: Data = desc.errorCorrectedPayload
let rawBarcodeData: NSData = rawBytes as NSData
print(rawBarcodeData)
}
I got the working data using the windows app bcTester.
If you split the data at offset 68 (78 9c
is the zlib
header, highlighted in my samples), the second part decompresses to plaintext, starting with U_HEAD01005
…
Example 1
correct sample data
23 55 54 30 31 30 30 38 30 30 30 30 30 36 30 2c 02 14 55 f2 2a 4b 56 40 78 09 81 23 3e 65 6c 15 cf fc 10 e6 7e e1 02 14 69 fa d7 36 68 09 ea 52 5c 6e 0e 69 94 2f 4b f1 87 97 26 00 00 00 00 00 30 34 32 39 78 9c 6d 91 c1 4e e3 30 10 86 f7 9c a7 b0 b4 97 dd 95 52 66 ec c4 71 10 aa 94 36 26 8d 94 56 a2 4d 41 70 41 06 02 8d 58 65 2b 13 b4 6f b2 27 1e 85 5b 5e 6c c7 0d b4 85 32 52 94 68 e6 fb 7f 8f ff 2c af 27 3a 49 01 01 42 01 a0 60 12 2c b3 33 e1 47 df f6 0a 04 08 0e 28 e9 e1 98 ea 54 3b 30 4f 81 03 a0 02 14 3c 54 ae 33 2a a8 83 4a 42 c8 39 5c cc d3 24 3d 1d 45 e5 be 4f d0 fb 90 a8 7f 4b 11 63 a0 e8 fb 42 67 67 57 22 bb fc 40 87 5f d3 20 16 c0 69 57 8c 0a d3 dc 5b d3 dc ae 6a 96 34 77 b6 32 34 88 68 10 ff fa 58 6e 41 1a 29 a7 e9 c1 ef 3b e9 f2 ba 2c 92 4b 0a 20 88 c5 7c 5c ba 3b 51 18 c8 41 88 18 00 04 e6 e3 23 3d 3e 35 2b fb 68 6c 5b 79 8b b5 b1 6b 5b d5 4f 4c 3f db 3f 6b 43 c1 11 8b 1b 96 1f 6c e4 21 d3 f6 af b9 5d 3d 55 4d 65 3d 4a 12 01 43 0a 82 ec b3 ee f5 77 5b 3f 3c 56 75 cb 20 18 80 18 b8 6b fa a8 de 3f 41 22 f1 1b 6b 0c 16 ed 80 4d 8d 7d b0 55 bb aa 1a 90 22 78 1b 81 9a 76 af 74 a4 6b 4a 49 fe a1 6b d2 25 a2 ad 7a 0f 89 b6 ba 03 4b e5 42 88 1c 1e e3 e4 98 9d 20 75 86 3f 76 9b fd 2c ea e6 ce 3c 33 3d c6 58 b0 f9 8e 08 b7 c4 d4 9f dc dc 33 94 c7 42 78 0e e3 ec 3c 4f 1c 88 0a 87 bd dc a3 68 11 c4 66 c9 58 7e 4e 93 bd 15 89 66 cb 39 cb ba 97 a2 cc 33 96 cf 58 f7 6f 34 f2 af ba 97 4c cf 1c 70 f0 1f 58 52 32 bf 2f 36 78 b7 61 94 93 3b 8e bb d3 b8 3f fc 0f 61 bb b8 e7
data from errorCorrectedPayload
02 2d 5f 11 91 51 11 11 41 67 7f e0 42 8a be 45 49 6a c8 0f 01 30 24 67 cc ad 82 b9 ff 82 1c cf dc 20 42 8d 3f 5a e6 cd 01 3d 53 f8 0d 12 e3 70 73 4c a1 7a 5f 8c 3c b9 30 00 04 01 00 40 30 34 32 39 78 9c 6d 91 c1 4e e3 30 10 86 f7 9c a7 b0 b4 97 dd 95 52 66 ec c4 71 10 aa 94 36 26 8d 94 56 a2 4d 41 70 41 06 02 8d 58 65 2b 13 b4 6f b2 27 1e 85 5b 5e 6c c7 0d b4 85 32 52 94 68 e6 fb 7f 8f ff 2c af 27 3a 49 01 01 42 01 a0 60 12 2c b3 33 e1 47 df f6 0a 04 08 0e 28 e9 e1 98 ea 54 3b 30 4f 81 03 a0 02 14 3c 54 ae 33 2a a8 83 4a 42 c8 39 5c cc d3 24 3d 1d 45 e5 be 4f d0 fb 90 a8 7f 4b 11 63 a0 e8 fb 42 67 67 57 22 bb fc 40 87 5f d3 20 16 c0 69 57 8c 0a d3 dc 5b d3 dc ae 6a 96 34 77 b6 32 34 88 68 10 ff fa 58 6e 41 1a 29 a7 e9 c1 ef 3b e9 f2 ba 2c 92 4b 0a 20 88 c5 7c 5c ba 3b 51 18 c8 41 88 18 00 12 73 71 91 9e 9f 1a 95 fd b4 36 2d bc c5 da d8 b5 ad ea a7 a6 1f ed 9f b5 a1 e0 88 c5 8d cb 0f b6 72 10 e9 fb 57 dc ae 9e aa a6 b2 9e a5 09 00 a1 85 41 76 59 f7 7a bb ad 9f 9e 2b 3a e5 90 0c 40 16 2e 1a fe aa 37 8f d0 48 bc 46 da c3 05 bb 60 13 63 5f 6c 15 6e ea 86 a4 08 9e 06 e0 66 9d ab dd 29 1a d2 92 7f a8 5a f4 89 68 ab 5e 83 e2 6d ae 80 d2 f9 50 a2 07 07 b8 f9 26 27 48 1d 61 8f dd a6 ff 4b 3a b9 b3 8f 0c cf 71 96 2c 3e 63 82 2d f1 35 27 f7 37 0c e5 31 d0 9e 03 b8 fb 0f 13 c7 22 02 a1 ef 77 28 da 04 71 19 b2 56 1f 93 a4 ef 45 62 59 b2 ce 72 ee a5 e8 b3 0c e5 b3 d6 3d db cd 3c ab ee a5 d3 33 c7 1c 3c 07 d6 14 8c af cb cd 9e 2d d8 65 24 ce e3 ae f4 ee 0f fe 81 ec 37 77 1c ff 80 00 00 00
decompressed text from sample data
U_HEAD01005300802P9QAN-40501201514560DEDE0080ID0200180104840080BL020357031204GW3HEMP906012015060120151021193517S0010018Fernweh-Ticket natS00200012S0030001AS00900051-0-0S01200010S0140002S2S0150006BerlinS0160011NeumünsterS0210038B-Hbf 8:16 ICE794/HH-Hbf 10:16 IC2224S0230013Krull AndreaS026000213S0270019***************0484S0280013Andrea#Krull S031001006.01.2015S032001006.01.2015S035000511160S0360003271
The data read from errorCorrectedPayload
however does not decompress and throws an error.
Example 2
correct sample data
23 55 54 30 31 30 30 38 30 30 30 30 30 36 30 2c 02 14 2f f7 0b f0 93 ab e5 cc fe a2 b6 f9 1b ec 9b dd 3c 1c 86 ce 02 14 1f 24 fb 65 db 51 4f 25 14 2b e1 fb 54 96 0a 31 f9 d5 61 0a 00 00 00 00 30 33 36 38 78 9c 65 90 cb 4e c3 30 10 45 59 e7 2b 2c b1 01 a4 94 19 3b b6 93 aa aa 94 a4 81 56 b4 2c fa 92 ba aa 42 71 49 d4 92 46 4e 10 3f c7 8e 1f 63 5c 8a a8 60 16 7e 5c 1f df 79 2c d6 c3 2c 1e 00 02 48 01 10 c2 6a 35 c3 08 7d 75 71 16 a8 91 73 40 09 c8 23 1c 64 83 cc 81 a3 01 70 00 0c 21 0a 02 85 4e 49 c6 a4 a0 40 10 c8 21 80 a5 7e 88 e6 f8 78 e6 c3 4f 3e 44 13 81 0a 25 97 2a 12 12 c4 0c b8 70 e2 b4 dc 14 ad b1 2c b6 d5 81 34 0d e4 c8 11 34 46 21 52 8d 21 fd d2 2e 1d bd 85 8e 77 dc e5 e9 d3 62 3d 1f c7 2b a2 84 96 d3 74 4e c5 41 74 4c 24 04 ed 54 d4 28 bd cd d2 bb bc b0 bb dc b6 c6 9b d5 b9 ad ad 29 1b 96 bd d9 43 9d d3 04 88 45 c7 72 7d 5e 88 87 2c b3 ef f9 a6 68 4c 65 ac 07 82 72 d0 30 02 f2 14 f7 9f 1f fb b6 7c d9 99 b2 65 5c 77 90 77 5c 83 3e 42 07 d0 1d 15 28 24 fe e8 0a e1 24 af aa c2 94 af a0 44 f0 23 06 b3 f2 50 81 52 8a 5c a5 13 90 fa a4 73 a0 dd 45 43 cf 5d fb 57 bf e6 d7 93 d8 1f 3e 6d 19 8a ae 90 6c 94 72 1d b1 e5 28 ee b2 24 6f cc 9e d6 67 96 6c 7b 88 a1 ec 27 c6 56 37 cb b2 a9 3d 37 6f 10 47 7f c5 ff 76 ce 4e f1 4f 4f 87 cc ff 0e d6 f9 81 18 15 ef cc dc 7c 81 fb fd 2f d3 2e 8b 94
data from errorCorrectedPayload
02 2d 5f 11 91 51 11 11 41 67 7f a0 42 85 fe e1 7e 12 75 7c b9 9f d4 56 df 23 7d 93 7b a7 83 90 d9 c0 42 83 e4 9f 6c bb 72 80 1a f8 0b 28 a1 5f 0f da a4 b0 51 8f ce ab 08 50 04 01 00 40 30 33 36 38 78 9c 65 90 cb 4e c3 30 10 45 59 e7 2b 2c b1 01 a4 94 19 3b b6 93 aa aa 94 a4 81 56 b4 2c fa 92 ba aa 42 71 49 d4 92 46 4e 10 3f c7 8e 1f 63 5c 8a a8 60 16 7e 5c 1f df 79 2c d6 c3 2c 1e 00 02 48 01 10 c2 6a 35 c3 08 7d 75 71 16 a8 91 73 40 09 c8 23 1c 64 83 cc 81 a3 01 70 00 0c 21 0a 02 85 4e 49 c6 a4 a0 40 10 c8 21 80 a5 7e 88 e6 f8 78 e6 c3 4f 3e 44 13 81 0a 25 97 2a 12 12 c4 0c b8 70 e2 b4 dc 14 ad b1 2c b6 d5 81 34 0d e4 c8 11 34 46 21 52 8d 21 fd d2 2e 1d bd 85 8e 77 dc e5 e9 d3 62 3d 1f c7 2b a2 84 96 d3 74 4e c5 41 74 4c 24 04 ed 54 d4 28 bd cd d2 bb bc b0 bb dc b6 c6 9b d5 b9 ad ad 29 1b 96 bd d9 43 9d d3 04 88 45 c7 72 7d 5e 88 87 2c b3 ef f9 a6 68 4c 65 ac 07 82 72 d0 30 02 f2 14 f7 9f 1f fb b6 7c d9 99 b2 65 5c 77 90 77 5c 83 3e 42 07 d0 1d 15 28 24 fe e8 0a e1 24 af aa c2 94 af a0 44 f0 23 06 b3 f2 50 81 52 8a 5c a5 13 90 fa a4 73 a0 dd 45 43 cf 5d fb 57 bf e6 d7 93 d8 1f 3e 6d 19 8a ae 90 6c 94 72 1d b1 e5 28 ee b2 24 6f cc 9e d6 67 96 6c 7b 88 a1 ec 27 c6 56 37 cb b2 a9 3d 37 6f 10 47 7f c5 ff 76 ce 4e f1 4f 4f 87 cc ff 0e d6 f9 81 18 15 ef cc dc 7c 81 fb fd 2f d3 2e 8b 94 ff 00
decompressed text from sample data
U_HEAD0100530080YYS191-61712201501291DEDE0080ID0200180944610080BL0201310312040V7K9T1N27122015100120161525693503S0230012Richter ArnoS027002021071981010820174461S0280012Arno#RichterU_TLAY010375RCT200090012033900031IC/ECFahrkarte
Sparpreis Europa0052031900027Richter Arno
1 Erwachsener
0301015040033Gültigkeit 27.12.2015-10.01.20160613011900008Mannheim0634011900004Sion066601050000110801047000070<1080>(27.12.2015)MA-Hbf 13:35 IC279 VIA: Basel Bad Bf<1185>Bern*Visp
1201035000062Sparpreis Europa Sparpreis Europa CH ------- . 0632010200002->
This time, the data from errorCorrectedPayload
decompresses perfectly to the exact same value as the sample!
Example 3
correct sample data
23 55 54 30 31 30 30 38 30 30 30 30 30 31 30 2c 02 14 0f 8d af c0 f7 89 7f d4 95 37 34 5a 68 6e c7 e5 a1 f4 2a 58 02 14 6a 03 b6 63 39 d2 9c eb 70 aa 4e 05 15 5e e8 bf b1 df 06 62 00 00 00 00 30 33 32 32 78 9c 6d 50 cb 4a 03 41 10 4c 04 1f 17 2f 9e f6 18 f0 20 28 1b ba 7b 66 77 66 bc b9 d9 8d 46 f4 10 96 04 3c 49 c0 a0 0b 71 13 36 93 80 8f 83 5f e5 0f f8 03 7e 80 1f 63 b7 c9 42 44 e7 32 35 d5 d5 dd 35 35 b8 bd c8 ce 52 40 80 48 01 58 e8 63 37 21 13 ea c6 c6 01 42 24 40 8d 4e 39 48 b3 34 13 61 2f 05 02 40 0b 18 69 1b 09 93 5c 31 a3 b4 02 c5 6a b8 19 5e c7 b6 7f d9 dd 98 43 66 35 a7 be 1d a0 01 b2 1a 4d 0e e2 00 5c 3e 1b 55 b3 6a 5c cc 99 e0 19 80 c8 40 09 48 18 38 06 31 86 18 6a 97 03 fe d4 81 81 66 40 39 31 62 1b 18 9d 7f bc 7b 5f 94 f7 e3 f2 a4 53 f8 27 a6 63 19 94 8c ab 49 51 53 c4 db 08 6b 65 8b e0 94 5c ab d7 41 e7 2c 17 79 21 ea c9 a8 9a 4f cb 96 2f 1e a7 fe 41 5a 62 59 83 8a 91 e1 ba 3b fe 7d 24 04 2e 59 69 5d f7 1c ae 46 e4 9c 87 38 25 d3 46 6c cb bf 99 a1 3f 0c 7b 97 e0 78 bf 92 4d 11 a2 f8 e6 58 87 03 c9 c6 9a c6 1d 47 d8 dc da b6 47 3e f0 bb 9f c1 12 5f 1a 4d 7c 0d 24 59 21 f7 be 76 f6 83 e5 f3 c1 1b 3f 16 ff 29 16 6b 85 8b bf 01 87 36 72 80
data from errorCorrectedPayload
02 2d 5f 11 91 51 11 11 19 67 7c 05 5c 08 50 3e 36 bf 03 de 25 ff 52 54 dc d1 69 a1 bb 1f 96 87 d0 a9 60 08 51 a8 0e d9 8c e7 4a 73 ad c2 a9 38 14 55 7b a2 fe c7 7c 19 88 00 04 01 00 58 19 99 19 3c 4e 36 a8 65 a5 01 a0 88 26 02 0f 8b 97 cf 7b 0c 78 10 14 0d dd 3d b3 3b b3 5e 5c ec c6 a3 7a 08 4b 02 1e 24 e0 50 05 b8 89 9b 49 c0 47 c1 af f2 87 fc 01 bf 40 0f b1 db e4 a1 22 73 99 1a ea ea ee 9a 9a dc 5e e4 67 29 20 40 24 00 ac 74 31 9b 90 89 f5 63 63 00 a1 12 20 46 a7 1c a4 59 9a 09 b0 97 82 81 20 05 8c 34 8d 84 c9 ae 18 d1 da 01 62 b5 5c 0c af 63 db 3f ec ee cc 21 b3 1a d3 df 0e d0 00 d9 0d 26 87 71 00 2e 1f 0d aa d9 b5 2e 66 4c f0 0c c0 64 20 04 a4 0c 1c 03 18 c3 0c 35 4b 81 ff 6a 40 c0 b3 20 1c 98 b1 0d 8c 4e bf de 3d af ca 7b f1 f9 52 29 fc 13 d3 31 8c c