Update EventParser.swift to Support CR LF#28
Conversation
|
Would you be able to add tests to verify your solution? |
|
Hi. I have updated the code to support mixed CRLF and LFLF with tests. But I don't know if we should ever support mixed contents. |
|
I don't think mixed content will ever be a case. I'll check the PR and merge it ASAP. Thank you! |
Recouse
left a comment
There was a problem hiding this comment.
Overall, it looks good, but I'm not sure about the replaceSubrange method.
I think we could consider a solution with a custom split method, where we iterate through possible separators, find a range for the separator, split the data, and repeat the process. It will be a split method added in #26, but wrapped in another loop.
To optimize, we could also assume that there won't be mixed separators and use the one from the first iteration.
| // now replace CR LF with LF LF for processing mixed content | ||
| var data = data | ||
| while let crlfRange = data.lastRange(of: [Self.cr, Self.lf]) { | ||
| data.replaceSubrange(crlfRange, with: [Self.lf]) |
There was a problem hiding this comment.
This method has O(n+m) complexity. Won't it affect performance on a large amount of data?
|
Would you like to implement the optimization on your side? Kinda busy right now :P |
|
Sure, I'll give it a shot, and maybe I'll open a new PR |
|
@Recouse think this PR will come in anytime soon? SSE spec says any of the 3 are supported "Lines must be separated by either a U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pair, a single U+000A LINE FEED (LF) character, or a single U+000D CARRIAGE RETURN (CR) character." so we are choking on spec compliant servers. Thanks! Have had terrific luck with your framework otherwise and appreciate you building it! |
|
Maybe you can change Parser implementation from |
|
I specifically used Data to avoid unnecessary conversions between Data and String. I have some drafts that add CRLF support, I haven't had the time to focus on them full-time, but I'll probably open a new PR as soon as it's ready. |
You can't. Some of the data starts with white spaces. It was fixed earlier. |
|
|
@Recouse I have replace all function with O(n) cplx so would you please update with me? |
|
I've been busy and haven't had time to review it yet. I'll take a look in the coming days, thanks for your contribution. |
|
Everything looks good to me. There's just one small improvement I'd like to suggest, removing the Data → String → Data conversions in the |
Added. |
|
Oops, I accidentally pushed everything to my repo instead of yours. |
PR for #27