From ede6f27bc38436865291452c80103f41cf1217f6 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 12 Nov 2024 23:01:42 +0400 Subject: [PATCH] refactor: rename PassThroughStream to DuplexStream (#33) --- ...hStream.swift => HybridDuplexStream.swift} | 2 +- packages/react-native-fast-io/nitro.json | 4 +-- .../android/FastIO+autolinking.cmake | 2 +- .../generated/ios/FastIO-Swift-Cxx-Bridge.cpp | 20 +++++------ .../generated/ios/FastIO-Swift-Cxx-Bridge.hpp | 20 +++++------ .../ios/FastIO-Swift-Cxx-Umbrella.hpp | 10 +++--- .../generated/ios/FastIOAutolinking.mm | 6 ++-- .../generated/ios/FastIOAutolinking.swift | 18 +++++----- ...ft.cpp => HybridDuplexStreamSpecSwift.cpp} | 4 +-- ...ft.hpp => HybridDuplexStreamSpecSwift.hpp} | 24 ++++++------- ...pec.swift => HybridDuplexStreamSpec.swift} | 10 +++--- ....swift => HybridDuplexStreamSpecCxx.swift} | 34 +++++++++---------- .../shared/c++/HybridDuplexStreamSpec.cpp | 24 +++++++++++++ ...eamSpec.hpp => HybridDuplexStreamSpec.hpp} | 18 +++++----- .../c++/HybridPassThroughStreamSpec.cpp | 24 ------------- .../src/native/streams.nitro.ts | 4 +-- .../react-native-fast-io/src/w3c/streams.ts | 8 ++--- 17 files changed, 116 insertions(+), 116 deletions(-) rename packages/react-native-fast-io/ios/{HybridPassThroughStream.swift => HybridDuplexStream.swift} (93%) rename packages/react-native-fast-io/nitrogen/generated/ios/c++/{HybridPassThroughStreamSpecSwift.cpp => HybridDuplexStreamSpecSwift.cpp} (72%) rename packages/react-native-fast-io/nitrogen/generated/ios/c++/{HybridPassThroughStreamSpecSwift.hpp => HybridDuplexStreamSpecSwift.hpp} (70%) rename packages/react-native-fast-io/nitrogen/generated/ios/swift/{HybridPassThroughStreamSpec.swift => HybridDuplexStreamSpec.swift} (68%) rename packages/react-native-fast-io/nitrogen/generated/ios/swift/{HybridPassThroughStreamSpecCxx.swift => HybridDuplexStreamSpecCxx.swift} (76%) create mode 100644 packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridDuplexStreamSpec.cpp rename packages/react-native-fast-io/nitrogen/generated/shared/c++/{HybridPassThroughStreamSpec.hpp => HybridDuplexStreamSpec.hpp} (75%) delete mode 100644 packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridPassThroughStreamSpec.cpp diff --git a/packages/react-native-fast-io/ios/HybridPassThroughStream.swift b/packages/react-native-fast-io/ios/HybridDuplexStream.swift similarity index 93% rename from packages/react-native-fast-io/ios/HybridPassThroughStream.swift rename to packages/react-native-fast-io/ios/HybridDuplexStream.swift index a662def..6c5e1c3 100644 --- a/packages/react-native-fast-io/ios/HybridPassThroughStream.swift +++ b/packages/react-native-fast-io/ios/HybridDuplexStream.swift @@ -7,7 +7,7 @@ import Foundation -class HybridPassThroughStream : HybridPassThroughStreamSpec { +class HybridDuplexStream : HybridDuplexStreamSpec { var inputStream: (any HybridInputStreamSpec) var outputStream: (any HybridOutputStreamSpec) diff --git a/packages/react-native-fast-io/nitro.json b/packages/react-native-fast-io/nitro.json index 91982a4..1aa663b 100644 --- a/packages/react-native-fast-io/nitro.json +++ b/packages/react-native-fast-io/nitro.json @@ -18,8 +18,8 @@ "Network": { "swift": "HybridNetwork" }, - "PassThroughStream": { - "swift": "HybridPassThroughStream" + "DuplexStream": { + "swift": "HybridDuplexStream" } } } diff --git a/packages/react-native-fast-io/nitrogen/generated/android/FastIO+autolinking.cmake b/packages/react-native-fast-io/nitrogen/generated/android/FastIO+autolinking.cmake index 713d16b..44c5171 100644 --- a/packages/react-native-fast-io/nitrogen/generated/android/FastIO+autolinking.cmake +++ b/packages/react-native-fast-io/nitrogen/generated/android/FastIO+autolinking.cmake @@ -31,7 +31,7 @@ target_sources( ../nitrogen/generated/shared/c++/HybridNetworkSpec.cpp ../nitrogen/generated/shared/c++/HybridInputStreamSpec.cpp ../nitrogen/generated/shared/c++/HybridOutputStreamSpec.cpp - ../nitrogen/generated/shared/c++/HybridPassThroughStreamSpec.cpp + ../nitrogen/generated/shared/c++/HybridDuplexStreamSpec.cpp ../nitrogen/generated/shared/c++/HybridWebSocketSpec.cpp ../nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.cpp # Android-specific Nitrogen C++ sources diff --git a/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Bridge.cpp b/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Bridge.cpp index 9f19d84..34e22f8 100644 --- a/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Bridge.cpp +++ b/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Bridge.cpp @@ -9,11 +9,11 @@ // Include C++ implementation defined types #include "FastIO-Swift-Cxx-Umbrella.hpp" +#include "HybridDuplexStreamSpecSwift.hpp" #include "HybridFileSystemSpecSwift.hpp" #include "HybridInputStreamSpecSwift.hpp" #include "HybridNetworkSpecSwift.hpp" #include "HybridOutputStreamSpecSwift.hpp" -#include "HybridPassThroughStreamSpecSwift.hpp" #include "HybridWebSocketManagerSpecSwift.hpp" #include "HybridWebSocketSpecSwift.hpp" #include @@ -84,20 +84,20 @@ namespace margelo::nitro::fastio::bridge::swift { return FastIO::HybridOutputStreamSpecCxxUnsafe::toUnsafe(swiftPart); } - // pragma MARK: std::shared_ptr - std::shared_ptr create_std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_(void* _Nonnull swiftUnsafePointer) { - FastIO::HybridPassThroughStreamSpecCxx swiftPart = FastIO::HybridPassThroughStreamSpecCxxUnsafe::fromUnsafe(swiftUnsafePointer); - return HybridContext::getOrCreate(swiftPart); + // pragma MARK: std::shared_ptr + std::shared_ptr create_std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_(void* _Nonnull swiftUnsafePointer) { + FastIO::HybridDuplexStreamSpecCxx swiftPart = FastIO::HybridDuplexStreamSpecCxxUnsafe::fromUnsafe(swiftUnsafePointer); + return HybridContext::getOrCreate(swiftPart); } - void* _Nonnull get_std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_(std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_ cppType) { - std::shared_ptr swiftWrapper = std::dynamic_pointer_cast(cppType); + void* _Nonnull get_std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_(std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_ cppType) { + std::shared_ptr swiftWrapper = std::dynamic_pointer_cast(cppType); #ifdef NITRO_DEBUG if (swiftWrapper == nullptr) [[unlikely]] { - throw std::runtime_error("Class \"HybridPassThroughStreamSpec\" is not implemented in Swift!"); + throw std::runtime_error("Class \"HybridDuplexStreamSpec\" is not implemented in Swift!"); } #endif - FastIO::HybridPassThroughStreamSpecCxx swiftPart = swiftWrapper->getSwiftPart(); - return FastIO::HybridPassThroughStreamSpecCxxUnsafe::toUnsafe(swiftPart); + FastIO::HybridDuplexStreamSpecCxx swiftPart = swiftWrapper->getSwiftPart(); + return FastIO::HybridDuplexStreamSpecCxxUnsafe::toUnsafe(swiftPart); } // pragma MARK: std::shared_ptr diff --git a/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Bridge.hpp b/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Bridge.hpp index 7155761..0020c5f 100644 --- a/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Bridge.hpp +++ b/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Bridge.hpp @@ -12,6 +12,8 @@ namespace NitroModules { class ArrayBufferHolder; } // Forward declaration of `ArrayBuffer` to properly resolve imports. namespace NitroModules { class ArrayBuffer; } +// Forward declaration of `HybridDuplexStreamSpec` to properly resolve imports. +namespace margelo::nitro::fastio { class HybridDuplexStreamSpec; } // Forward declaration of `HybridFileSystemSpec` to properly resolve imports. namespace margelo::nitro::fastio { class HybridFileSystemSpec; } // Forward declaration of `HybridInputStreamSpec` to properly resolve imports. @@ -20,8 +22,6 @@ namespace margelo::nitro::fastio { class HybridInputStreamSpec; } namespace margelo::nitro::fastio { class HybridNetworkSpec; } // Forward declaration of `HybridOutputStreamSpec` to properly resolve imports. namespace margelo::nitro::fastio { class HybridOutputStreamSpec; } -// Forward declaration of `HybridPassThroughStreamSpec` to properly resolve imports. -namespace margelo::nitro::fastio { class HybridPassThroughStreamSpec; } // Forward declaration of `HybridWebSocketManagerSpec` to properly resolve imports. namespace margelo::nitro::fastio { class HybridWebSocketManagerSpec; } // Forward declaration of `HybridWebSocketSpec` to properly resolve imports. @@ -30,6 +30,8 @@ namespace margelo::nitro::fastio { class HybridWebSocketSpec; } namespace margelo::nitro::fastio { struct NativeFilePickerOptions; } // Forward declarations of Swift defined types +// Forward declaration of `HybridDuplexStreamSpecCxx` to properly resolve imports. +namespace FastIO { class HybridDuplexStreamSpecCxx; } // Forward declaration of `HybridFileSystemSpecCxx` to properly resolve imports. namespace FastIO { class HybridFileSystemSpecCxx; } // Forward declaration of `HybridInputStreamSpecCxx` to properly resolve imports. @@ -38,19 +40,17 @@ namespace FastIO { class HybridInputStreamSpecCxx; } namespace FastIO { class HybridNetworkSpecCxx; } // Forward declaration of `HybridOutputStreamSpecCxx` to properly resolve imports. namespace FastIO { class HybridOutputStreamSpecCxx; } -// Forward declaration of `HybridPassThroughStreamSpecCxx` to properly resolve imports. -namespace FastIO { class HybridPassThroughStreamSpecCxx; } // Forward declaration of `HybridWebSocketManagerSpecCxx` to properly resolve imports. namespace FastIO { class HybridWebSocketManagerSpecCxx; } // Forward declaration of `HybridWebSocketSpecCxx` to properly resolve imports. namespace FastIO { class HybridWebSocketSpecCxx; } // Include C++ defined types +#include "HybridDuplexStreamSpec.hpp" #include "HybridFileSystemSpec.hpp" #include "HybridInputStreamSpec.hpp" #include "HybridNetworkSpec.hpp" #include "HybridOutputStreamSpec.hpp" -#include "HybridPassThroughStreamSpec.hpp" #include "HybridWebSocketManagerSpec.hpp" #include "HybridWebSocketSpec.hpp" #include "NativeFilePickerOptions.hpp" @@ -167,13 +167,13 @@ namespace margelo::nitro::fastio::bridge::swift { std::shared_ptr create_std__shared_ptr_margelo__nitro__fastio__HybridOutputStreamSpec_(void* _Nonnull swiftUnsafePointer); void* _Nonnull get_std__shared_ptr_margelo__nitro__fastio__HybridOutputStreamSpec_(std__shared_ptr_margelo__nitro__fastio__HybridOutputStreamSpec_ cppType); - // pragma MARK: std::shared_ptr + // pragma MARK: std::shared_ptr /** - * Specialized version of `std::shared_ptr`. + * Specialized version of `std::shared_ptr`. */ - using std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_ = std::shared_ptr; - std::shared_ptr create_std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_(void* _Nonnull swiftUnsafePointer); - void* _Nonnull get_std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_(std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_ cppType); + using std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_ = std::shared_ptr; + std::shared_ptr create_std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_(void* _Nonnull swiftUnsafePointer); + void* _Nonnull get_std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_(std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_ cppType); // pragma MARK: std::function /** diff --git a/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Umbrella.hpp b/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Umbrella.hpp index 42fcc71..571881b 100644 --- a/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Umbrella.hpp +++ b/packages/react-native-fast-io/nitrogen/generated/ios/FastIO-Swift-Cxx-Umbrella.hpp @@ -10,6 +10,8 @@ // Forward declarations of C++ defined types // Forward declaration of `ArrayBuffer` to properly resolve imports. namespace NitroModules { class ArrayBuffer; } +// Forward declaration of `HybridDuplexStreamSpec` to properly resolve imports. +namespace margelo::nitro::fastio { class HybridDuplexStreamSpec; } // Forward declaration of `HybridFileSystemSpec` to properly resolve imports. namespace margelo::nitro::fastio { class HybridFileSystemSpec; } // Forward declaration of `HybridInputStreamSpec` to properly resolve imports. @@ -18,8 +20,6 @@ namespace margelo::nitro::fastio { class HybridInputStreamSpec; } namespace margelo::nitro::fastio { class HybridNetworkSpec; } // Forward declaration of `HybridOutputStreamSpec` to properly resolve imports. namespace margelo::nitro::fastio { class HybridOutputStreamSpec; } -// Forward declaration of `HybridPassThroughStreamSpec` to properly resolve imports. -namespace margelo::nitro::fastio { class HybridPassThroughStreamSpec; } // Forward declaration of `HybridWebSocketManagerSpec` to properly resolve imports. namespace margelo::nitro::fastio { class HybridWebSocketManagerSpec; } // Forward declaration of `HybridWebSocketSpec` to properly resolve imports. @@ -36,11 +36,11 @@ namespace margelo::nitro::fastio { struct RequestOptions; } namespace margelo::nitro::fastio { enum class WellKnownDirectory; } // Include C++ defined types +#include "HybridDuplexStreamSpec.hpp" #include "HybridFileSystemSpec.hpp" #include "HybridInputStreamSpec.hpp" #include "HybridNetworkSpec.hpp" #include "HybridOutputStreamSpec.hpp" -#include "HybridPassThroughStreamSpec.hpp" #include "HybridWebSocketManagerSpec.hpp" #include "HybridWebSocketSpec.hpp" #include "Metadata.hpp" @@ -66,6 +66,8 @@ namespace margelo::nitro::fastio { enum class WellKnownDirectory; } #include // Forward declarations of Swift defined types +// Forward declaration of `HybridDuplexStreamSpecCxx` to properly resolve imports. +namespace FastIO { class HybridDuplexStreamSpecCxx; } // Forward declaration of `HybridFileSystemSpecCxx` to properly resolve imports. namespace FastIO { class HybridFileSystemSpecCxx; } // Forward declaration of `HybridInputStreamSpecCxx` to properly resolve imports. @@ -74,8 +76,6 @@ namespace FastIO { class HybridInputStreamSpecCxx; } namespace FastIO { class HybridNetworkSpecCxx; } // Forward declaration of `HybridOutputStreamSpecCxx` to properly resolve imports. namespace FastIO { class HybridOutputStreamSpecCxx; } -// Forward declaration of `HybridPassThroughStreamSpecCxx` to properly resolve imports. -namespace FastIO { class HybridPassThroughStreamSpecCxx; } // Forward declaration of `HybridWebSocketManagerSpecCxx` to properly resolve imports. namespace FastIO { class HybridWebSocketManagerSpecCxx; } // Forward declaration of `HybridWebSocketSpecCxx` to properly resolve imports. diff --git a/packages/react-native-fast-io/nitrogen/generated/ios/FastIOAutolinking.mm b/packages/react-native-fast-io/nitrogen/generated/ios/FastIOAutolinking.mm index b5d5fd3..4d57e68 100644 --- a/packages/react-native-fast-io/nitrogen/generated/ios/FastIOAutolinking.mm +++ b/packages/react-native-fast-io/nitrogen/generated/ios/FastIOAutolinking.mm @@ -13,7 +13,7 @@ #include "HybridWebSocketManagerSpecSwift.hpp" #include "HybridFileSystemSpecSwift.hpp" #include "HybridNetworkSpecSwift.hpp" -#include "HybridPassThroughStreamSpecSwift.hpp" +#include "HybridDuplexStreamSpecSwift.hpp" @interface FastIOAutolinking : NSObject @end @@ -46,9 +46,9 @@ + (void) load { } ); HybridObjectRegistry::registerHybridObjectConstructor( - "PassThroughStream", + "DuplexStream", []() -> std::shared_ptr { - std::shared_ptr hybridObject = FastIO::FastIOAutolinking::createPassThroughStream(); + std::shared_ptr hybridObject = FastIO::FastIOAutolinking::createDuplexStream(); return hybridObject; } ); diff --git a/packages/react-native-fast-io/nitrogen/generated/ios/FastIOAutolinking.swift b/packages/react-native-fast-io/nitrogen/generated/ios/FastIOAutolinking.swift index 6ed9c8f..117f1ba 100644 --- a/packages/react-native-fast-io/nitrogen/generated/ios/FastIOAutolinking.swift +++ b/packages/react-native-fast-io/nitrogen/generated/ios/FastIOAutolinking.swift @@ -57,18 +57,18 @@ public final class FastIOAutolinking { } /** - * Creates an instance of a Swift class that implements `HybridPassThroughStreamSpec`, - * and wraps it in a Swift class that can directly interop with C++ (`HybridPassThroughStreamSpecCxx`) + * Creates an instance of a Swift class that implements `HybridDuplexStreamSpec`, + * and wraps it in a Swift class that can directly interop with C++ (`HybridDuplexStreamSpecCxx`) * * This is generated by Nitrogen and will initialize the class specified - * in the `"autolinking"` property of `nitro.json` (in this case, `HybridPassThroughStream`). + * in the `"autolinking"` property of `nitro.json` (in this case, `HybridDuplexStream`). */ - public static func createPassThroughStream() -> bridge.std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_ { - let hybridObject = HybridPassThroughStream() - return { () -> bridge.std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_ in - let __cxxWrapped = HybridPassThroughStreamSpecCxx(hybridObject) - let __pointer = HybridPassThroughStreamSpecCxxUnsafe.toUnsafe(__cxxWrapped) - return bridge.create_std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_(__pointer) + public static func createDuplexStream() -> bridge.std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_ { + let hybridObject = HybridDuplexStream() + return { () -> bridge.std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_ in + let __cxxWrapped = HybridDuplexStreamSpecCxx(hybridObject) + let __pointer = HybridDuplexStreamSpecCxxUnsafe.toUnsafe(__cxxWrapped) + return bridge.create_std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_(__pointer) }() } } diff --git a/packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridPassThroughStreamSpecSwift.cpp b/packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridDuplexStreamSpecSwift.cpp similarity index 72% rename from packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridPassThroughStreamSpecSwift.cpp rename to packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridDuplexStreamSpecSwift.cpp index 95fb03b..cb0efe5 100644 --- a/packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridPassThroughStreamSpecSwift.cpp +++ b/packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridDuplexStreamSpecSwift.cpp @@ -1,11 +1,11 @@ /// -/// HybridPassThroughStreamSpecSwift.cpp +/// HybridDuplexStreamSpecSwift.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. /// https://github.com/mrousavy/nitro /// Copyright © 2024 Marc Rousavy @ Margelo /// -#include "HybridPassThroughStreamSpecSwift.hpp" +#include "HybridDuplexStreamSpecSwift.hpp" namespace margelo::nitro::fastio { } // namespace margelo::nitro::fastio diff --git a/packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridPassThroughStreamSpecSwift.hpp b/packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridDuplexStreamSpecSwift.hpp similarity index 70% rename from packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridPassThroughStreamSpecSwift.hpp rename to packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridDuplexStreamSpecSwift.hpp index 3f564a2..c7f0090 100644 --- a/packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridPassThroughStreamSpecSwift.hpp +++ b/packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridDuplexStreamSpecSwift.hpp @@ -1,5 +1,5 @@ /// -/// HybridPassThroughStreamSpecSwift.hpp +/// HybridDuplexStreamSpecSwift.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. /// https://github.com/mrousavy/nitro /// Copyright © 2024 Marc Rousavy @ Margelo @@ -7,10 +7,10 @@ #pragma once -#include "HybridPassThroughStreamSpec.hpp" +#include "HybridDuplexStreamSpec.hpp" -// Forward declaration of `HybridPassThroughStreamSpecCxx` to properly resolve imports. -namespace FastIO { class HybridPassThroughStreamSpecCxx; } +// Forward declaration of `HybridDuplexStreamSpecCxx` to properly resolve imports. +namespace FastIO { class HybridDuplexStreamSpecCxx; } // Forward declaration of `HybridInputStreamSpec` to properly resolve imports. namespace margelo::nitro::fastio { class HybridInputStreamSpec; } @@ -32,25 +32,25 @@ namespace margelo::nitro::fastio { class HybridOutputStreamSpec; } namespace margelo::nitro::fastio { /** - * The C++ part of HybridPassThroughStreamSpecCxx.swift. + * The C++ part of HybridDuplexStreamSpecCxx.swift. * - * HybridPassThroughStreamSpecSwift (C++) accesses HybridPassThroughStreamSpecCxx (Swift), and might + * HybridDuplexStreamSpecSwift (C++) accesses HybridDuplexStreamSpecCxx (Swift), and might * contain some additional bridging code for C++ <> Swift interop. * * Since this obviously introduces an overhead, I hope at some point in - * the future, HybridPassThroughStreamSpecCxx can directly inherit from the C++ class HybridPassThroughStreamSpec + * the future, HybridDuplexStreamSpecCxx can directly inherit from the C++ class HybridDuplexStreamSpec * to simplify the whole structure and memory management. */ - class HybridPassThroughStreamSpecSwift: public virtual HybridPassThroughStreamSpec { + class HybridDuplexStreamSpecSwift: public virtual HybridDuplexStreamSpec { public: // Constructor from a Swift instance - explicit HybridPassThroughStreamSpecSwift(const FastIO::HybridPassThroughStreamSpecCxx& swiftPart): - HybridObject(HybridPassThroughStreamSpec::TAG), + explicit HybridDuplexStreamSpecSwift(const FastIO::HybridDuplexStreamSpecCxx& swiftPart): + HybridObject(HybridDuplexStreamSpec::TAG), _swiftPart(swiftPart) { } public: // Get the Swift part - inline FastIO::HybridPassThroughStreamSpecCxx getSwiftPart() noexcept { return _swiftPart; } + inline FastIO::HybridDuplexStreamSpecCxx getSwiftPart() noexcept { return _swiftPart; } public: // Get memory pressure @@ -80,7 +80,7 @@ namespace margelo::nitro::fastio { private: - FastIO::HybridPassThroughStreamSpecCxx _swiftPart; + FastIO::HybridDuplexStreamSpecCxx _swiftPart; }; } // namespace margelo::nitro::fastio diff --git a/packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridPassThroughStreamSpec.swift b/packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridDuplexStreamSpec.swift similarity index 68% rename from packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridPassThroughStreamSpec.swift rename to packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridDuplexStreamSpec.swift index 1fa69ec..ece0171 100644 --- a/packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridPassThroughStreamSpec.swift +++ b/packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridDuplexStreamSpec.swift @@ -1,5 +1,5 @@ /// -/// HybridPassThroughStreamSpec.swift +/// HybridDuplexStreamSpec.swift /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. /// https://github.com/mrousavy/nitro /// Copyright © 2024 Marc Rousavy @ Margelo @@ -9,12 +9,12 @@ import Foundation import NitroModules /** - * A Swift protocol representing the PassThroughStream HybridObject. - * Implement this protocol to create Swift-based instances of PassThroughStream. + * A Swift protocol representing the DuplexStream HybridObject. + * Implement this protocol to create Swift-based instances of DuplexStream. * * When implementing this protocol, make sure to initialize `hybridContext` - example: * ``` - * public class HybridPassThroughStream : HybridPassThroughStreamSpec { + * public class HybridDuplexStream : HybridDuplexStreamSpec { * // Initialize HybridContext * var hybridContext = margelo.nitro.HybridContext() * @@ -27,7 +27,7 @@ import NitroModules * } * ``` */ -public protocol HybridPassThroughStreamSpec: AnyObject, HybridObjectSpec { +public protocol HybridDuplexStreamSpec: AnyObject, HybridObjectSpec { // Properties var inputStream: (any HybridInputStreamSpec) { get set } var outputStream: (any HybridOutputStreamSpec) { get set } diff --git a/packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridPassThroughStreamSpecCxx.swift b/packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridDuplexStreamSpecCxx.swift similarity index 76% rename from packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridPassThroughStreamSpecCxx.swift rename to packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridDuplexStreamSpecCxx.swift index 96161ff..742a7b8 100644 --- a/packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridPassThroughStreamSpecCxx.swift +++ b/packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridDuplexStreamSpecCxx.swift @@ -1,5 +1,5 @@ /// -/// HybridPassThroughStreamSpecCxx.swift +/// HybridDuplexStreamSpecCxx.swift /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. /// https://github.com/mrousavy/nitro /// Copyright © 2024 Marc Rousavy @ Margelo @@ -9,31 +9,31 @@ import Foundation import NitroModules /** - * Helper class for converting instances of `HybridPassThroughStreamSpecCxx` from- and to unsafe pointers. + * Helper class for converting instances of `HybridDuplexStreamSpecCxx` from- and to unsafe pointers. * This is useful to pass Swift classes to C++, without having to strongly type the C++ function signature. * The actual Swift type can be included in the .cpp file, without having to forward-declare anything in .hpp. */ -public final class HybridPassThroughStreamSpecCxxUnsafe { +public final class HybridDuplexStreamSpecCxxUnsafe { /** - * Casts a `HybridPassThroughStreamSpecCxx` instance to a retained unsafe raw pointer. + * Casts a `HybridDuplexStreamSpecCxx` instance to a retained unsafe raw pointer. * This acquires one additional strong reference on the object! */ - public static func toUnsafe(_ instance: HybridPassThroughStreamSpecCxx) -> UnsafeMutableRawPointer { + public static func toUnsafe(_ instance: HybridDuplexStreamSpecCxx) -> UnsafeMutableRawPointer { return Unmanaged.passRetained(instance).toOpaque() } /** - * Casts an unsafe pointer to a `HybridPassThroughStreamSpecCxx`. - * The pointer has to be a retained opaque `Unmanaged`. + * Casts an unsafe pointer to a `HybridDuplexStreamSpecCxx`. + * The pointer has to be a retained opaque `Unmanaged`. * This removes one strong reference from the object! */ - public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridPassThroughStreamSpecCxx { - return Unmanaged.fromOpaque(pointer).takeRetainedValue() + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridDuplexStreamSpecCxx { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() } } /** - * A class implementation that bridges HybridPassThroughStreamSpec over to C++. + * A class implementation that bridges HybridDuplexStreamSpec over to C++. * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined. * * Also, some Swift types need to be bridged with special handling: @@ -41,7 +41,7 @@ public final class HybridPassThroughStreamSpecCxxUnsafe { * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper * - Throwing methods need to be wrapped with a Result type, as exceptions cannot be propagated to C++ */ -public class HybridPassThroughStreamSpecCxx { +public class HybridDuplexStreamSpecCxx { /** * The Swift <> C++ bridge's namespace (`margelo::nitro::fastio::bridge::swift`) * from `FastIO-Swift-Cxx-Bridge.hpp`. @@ -50,24 +50,24 @@ public class HybridPassThroughStreamSpecCxx { public typealias bridge = margelo.nitro.fastio.bridge.swift /** - * Holds an instance of the `HybridPassThroughStreamSpec` Swift protocol. + * Holds an instance of the `HybridDuplexStreamSpec` Swift protocol. */ - private var __implementation: any HybridPassThroughStreamSpec + private var __implementation: any HybridDuplexStreamSpec /** - * Create a new `HybridPassThroughStreamSpecCxx` that wraps the given `HybridPassThroughStreamSpec`. + * Create a new `HybridDuplexStreamSpecCxx` that wraps the given `HybridDuplexStreamSpec`. * All properties and methods bridge to C++ types. */ - public init(_ implementation: some HybridPassThroughStreamSpec) { + public init(_ implementation: some HybridDuplexStreamSpec) { self.__implementation = implementation /* no base class */ } /** - * Get the actual `HybridPassThroughStreamSpec` instance this class wraps. + * Get the actual `HybridDuplexStreamSpec` instance this class wraps. */ @inline(__always) - public func getHybridPassThroughStreamSpec() -> any HybridPassThroughStreamSpec { + public func getHybridDuplexStreamSpec() -> any HybridDuplexStreamSpec { return __implementation } diff --git a/packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridDuplexStreamSpec.cpp b/packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridDuplexStreamSpec.cpp new file mode 100644 index 0000000..9a67e5c --- /dev/null +++ b/packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridDuplexStreamSpec.cpp @@ -0,0 +1,24 @@ +/// +/// HybridDuplexStreamSpec.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +#include "HybridDuplexStreamSpec.hpp" + +namespace margelo::nitro::fastio { + + void HybridDuplexStreamSpec::loadHybridMethods() { + // load base methods/properties + HybridObject::loadHybridMethods(); + // load custom methods/properties + registerHybrids(this, [](Prototype& prototype) { + prototype.registerHybridGetter("inputStream", &HybridDuplexStreamSpec::getInputStream); + prototype.registerHybridSetter("inputStream", &HybridDuplexStreamSpec::setInputStream); + prototype.registerHybridGetter("outputStream", &HybridDuplexStreamSpec::getOutputStream); + prototype.registerHybridSetter("outputStream", &HybridDuplexStreamSpec::setOutputStream); + }); + } + +} // namespace margelo::nitro::fastio diff --git a/packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridPassThroughStreamSpec.hpp b/packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridDuplexStreamSpec.hpp similarity index 75% rename from packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridPassThroughStreamSpec.hpp rename to packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridDuplexStreamSpec.hpp index 8e5a87c..f5efb72 100644 --- a/packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridPassThroughStreamSpec.hpp +++ b/packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridDuplexStreamSpec.hpp @@ -1,5 +1,5 @@ /// -/// HybridPassThroughStreamSpec.hpp +/// HybridDuplexStreamSpec.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. /// https://github.com/mrousavy/nitro /// Copyright © 2024 Marc Rousavy @ Margelo @@ -27,25 +27,25 @@ namespace margelo::nitro::fastio { using namespace margelo::nitro; /** - * An abstract base class for `PassThroughStream` - * Inherit this class to create instances of `HybridPassThroughStreamSpec` in C++. + * An abstract base class for `DuplexStream` + * Inherit this class to create instances of `HybridDuplexStreamSpec` in C++. * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. * @example * ```cpp - * class HybridPassThroughStream: public HybridPassThroughStreamSpec { + * class HybridDuplexStream: public HybridDuplexStreamSpec { * public: - * HybridPassThroughStream(...): HybridObject(TAG) { ... } + * HybridDuplexStream(...): HybridObject(TAG) { ... } * // ... * }; * ``` */ - class HybridPassThroughStreamSpec: public virtual HybridObject { + class HybridDuplexStreamSpec: public virtual HybridObject { public: // Constructor - explicit HybridPassThroughStreamSpec(): HybridObject(TAG) { } + explicit HybridDuplexStreamSpec(): HybridObject(TAG) { } // Destructor - virtual ~HybridPassThroughStreamSpec() { } + virtual ~HybridDuplexStreamSpec() { } public: // Properties @@ -64,7 +64,7 @@ namespace margelo::nitro::fastio { protected: // Tag for logging - static constexpr auto TAG = "PassThroughStream"; + static constexpr auto TAG = "DuplexStream"; }; } // namespace margelo::nitro::fastio diff --git a/packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridPassThroughStreamSpec.cpp b/packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridPassThroughStreamSpec.cpp deleted file mode 100644 index 82d829e..0000000 --- a/packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridPassThroughStreamSpec.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/// -/// HybridPassThroughStreamSpec.cpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © 2024 Marc Rousavy @ Margelo -/// - -#include "HybridPassThroughStreamSpec.hpp" - -namespace margelo::nitro::fastio { - - void HybridPassThroughStreamSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridGetter("inputStream", &HybridPassThroughStreamSpec::getInputStream); - prototype.registerHybridSetter("inputStream", &HybridPassThroughStreamSpec::setInputStream); - prototype.registerHybridGetter("outputStream", &HybridPassThroughStreamSpec::getOutputStream); - prototype.registerHybridSetter("outputStream", &HybridPassThroughStreamSpec::setOutputStream); - }); - } - -} // namespace margelo::nitro::fastio diff --git a/packages/react-native-fast-io/src/native/streams.nitro.ts b/packages/react-native-fast-io/src/native/streams.nitro.ts index 4293348..12da284 100644 --- a/packages/react-native-fast-io/src/native/streams.nitro.ts +++ b/packages/react-native-fast-io/src/native/streams.nitro.ts @@ -16,9 +16,9 @@ export interface OutputStream extends HybridObject<{ ios: 'swift' }> { close(): void } -export interface PassThroughStream extends HybridObject<{ ios: 'swift' }> { +export interface DuplexStream extends HybridObject<{ ios: 'swift' }> { inputStream: InputStream outputStream: OutputStream } -export const PassThroughStream = getHybridObjectConstructor('PassThroughStream') +export const DuplexStream = getHybridObjectConstructor('PassThroughStream') diff --git a/packages/react-native-fast-io/src/w3c/streams.ts b/packages/react-native-fast-io/src/w3c/streams.ts index 21ec570..420580f 100644 --- a/packages/react-native-fast-io/src/w3c/streams.ts +++ b/packages/react-native-fast-io/src/w3c/streams.ts @@ -1,4 +1,4 @@ -import { InputStream, OutputStream, PassThroughStream } from '../native/streams.nitro' +import { DuplexStream, InputStream, OutputStream } from '../native/streams.nitro' const CHUNK_SIZE = 1024 * 64 @@ -59,10 +59,10 @@ export const toWritableStream = (outputStream: OutputStream) => { } export const fromReadableStream = (stream: ReadableStream): InputStream => { - const passThroughStream = new PassThroughStream() + const duplexStream = new DuplexStream() - const writableStream = toWritableStream(passThroughStream.outputStream) + const writableStream = toWritableStream(duplexStream.outputStream) stream.pipeTo(writableStream) - return passThroughStream.inputStream + return duplexStream.inputStream }