 private func string(from pointer: UnsafePointer<UInt8>!) -> String? {
     return String.decodeCString(pointer, as: UTF8.self, repairingInvalidCodeUnits: true)?.result
 }
+
+#if swift(>=4.2)
+#if compiler(>=5) && canImport(Darwin)
+#else
+private extension Data {
+    func withUnsafeBytes<Result>(_ apply: (UnsafeRawBufferPointer) throws -> Result) rethrows -> Result {
+        return try withUnsafeBytes {
+            try apply(UnsafeRawBufferPointer(start: $0, count: count))
+        }
+    }
+}
+#endif
+#else
+private extension Data {
+    func withUnsafeBytes<Result>(_ apply: (UnsafeRawBufferPointer) throws -> Result) rethrows -> Result {
+        return try withUnsafeBytes {
+            try apply(UnsafeRawBufferPointer(start: $0, count: count))
+        }
+    }
+}
+#endif

        }
    }

    @discardableResult
    func parse() throws -> Event {
        let event = Event()

        yaml_parser_initialize(&parser)
#if USE_UTF8
        yaml_parser_set_encoding(&parser, YAML_UTF8_ENCODING)
        utf8Slice = string.utf8CString.dropLast()
        try utf8Slice.withUnsafeBytes(startParse(with:))
#else
        // use native endian
        let isLittleEndian = 1 == 1.littleEndian
        yaml_parser_set_encoding(&parser, isLittleEndian ? YAML_UTF16LE_ENCODING : YAML_UTF16BE_ENCODING)
        let encoding: String.Encoding = isLittleEndian ? .utf16LittleEndian : .utf16BigEndian
        data = yaml.data(using: encoding)!
        try data.withUnsafeBytes(startParse(with:))
#endif
    }

