Re: Data, enumerateBytes: separate blocks?
Re: Data, enumerateBytes: separate blocks?
- Subject: Re: Data, enumerateBytes: separate blocks?
- From: Daryle Walker <email@hidden>
- Date: Thu, 21 Dec 2017 21:04:32 -0500
> On Dec 19, 2017, at 8:08 PM, Quincey Morris
> <email@hidden> wrote:
>
> On Dec 19, 2017, at 14:57 , Daryle Walker <email@hidden
> <mailto:email@hidden>> wrote:
>>
>> What are the hoops/bridges required?
>
> I think I was referring to what Wim Lewis said, which is that you can create
> DispatchData values (or perhaps dispatch_data_t objects), but you’re going to
> have to forcibly cast from dispatch_data_t to its superclass, and then bridge
> that to Data.
>
> However, if you’re going to the trouble of creating DispatchData values, you
> may as well use those directly, rather than bridging across to Data. The
> decision may depend on exactly which APIs you need to use to process the data.
I need to test when multiple blocks are used:
> // Find the first occurance of each potential terminator byte value.
> var firstCr, firstLf: Index?
> enumerateBytes { buffer, start, stop in
> if let localLf = buffer.index(of: ParsingQueue.Constants.lf) {
> firstLf = start.advanced(by: buffer.startIndex.distance(to:
> localLf))
> stop = true
> }
>
> if let firstCrIndex = firstCr, firstCrIndex.distance(to:
> start.advanced(by: buffer.count)) > 2 {
> // No block after this current one could find a LF close
> enough to form CR-LF or CR-CR-LF.
> stop = true
> } else if let localCr = buffer.index(of:
> ParsingQueue.Constants.cr) {
> firstCr = start.advanced(by: buffer.startIndex.distance(to:
> localCr))
> stop = true
> }
> }
(This is in an extension of Data.) Right now, I have no way to activate the
second IF-block for testing.
—
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden