Some of the cloud service may use \r\n as the separator when processing events.
Here is the modified code that I suggested to change.
private func splitBuffer(for data: Data) -> (completeData: [Data], remainingData: Data) {
let possibleSeparators: [[UInt8]] = [
[Self.lf, Self.lf],
[Self.cr, Self.lf],
]
var rawMessages = [Data]()
for separator in possibleSeparators {
// If event separator is not present do not parse any unfinished messages
guard let lastSeparator = data.lastRange(of: separator) else { continue }
let bufferRange = data.startIndex ..< lastSeparator.upperBound
let remainingRange = lastSeparator.upperBound ..< data.endIndex
if #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, visionOS 1.0, *) {
rawMessages = data[bufferRange].split(separator: separator)
} else {
rawMessages = data[bufferRange].split(by: separator)
}
return (rawMessages, data[remainingRange])
}
return ([], data)
}
Some of the cloud service may use \r\n as the separator when processing events.
Here is the modified code that I suggested to change.