react-native-nitro-net 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +133 -0
  2. package/android/CMakeLists.txt +29 -0
  3. package/android/OnLoad.cpp +6 -0
  4. package/android/build.gradle +72 -0
  5. package/android/gradle.properties +6 -0
  6. package/android/libs/arm64-v8a/librust_c_net.so +0 -0
  7. package/android/libs/armeabi-v7a/librust_c_net.so +0 -0
  8. package/android/libs/x86/librust_c_net.so +0 -0
  9. package/android/libs/x86_64/librust_c_net.so +0 -0
  10. package/android/src/main/AndroidManifest.xml +3 -0
  11. package/android/src/main/java/com/margelo/nitro/net/NitroNetPackage.java +32 -0
  12. package/cpp/HybridNetDriver.cpp +5 -0
  13. package/cpp/HybridNetDriver.hpp +42 -0
  14. package/cpp/HybridNetServerDriver.cpp +5 -0
  15. package/cpp/HybridNetServerDriver.hpp +114 -0
  16. package/cpp/HybridNetSocketDriver.cpp +6 -0
  17. package/cpp/HybridNetSocketDriver.hpp +132 -0
  18. package/cpp/NetBindings.hpp +68 -0
  19. package/cpp/NetManager.hpp +160 -0
  20. package/ios/Frameworks/RustCNet.xcframework/Info.plist +44 -0
  21. package/ios/Frameworks/RustCNet.xcframework/ios-arm64/RustCNet.framework/Info.plist +20 -0
  22. package/ios/Frameworks/RustCNet.xcframework/ios-arm64/RustCNet.framework/RustCNet +0 -0
  23. package/ios/Frameworks/RustCNet.xcframework/ios-arm64_x86_64-simulator/RustCNet.framework/Info.plist +20 -0
  24. package/ios/Frameworks/RustCNet.xcframework/ios-arm64_x86_64-simulator/RustCNet.framework/RustCNet +0 -0
  25. package/lib/Driver.d.ts +2 -0
  26. package/lib/Driver.js +5 -0
  27. package/lib/Net.nitro.d.ts +85 -0
  28. package/lib/Net.nitro.js +21 -0
  29. package/lib/index.d.ts +162 -0
  30. package/lib/index.js +781 -0
  31. package/nitrogen/generated/.gitattributes +1 -0
  32. package/nitrogen/generated/android/RustCNet+autolinking.cmake +86 -0
  33. package/nitrogen/generated/android/RustCNet+autolinking.gradle +27 -0
  34. package/nitrogen/generated/android/RustCNetOnLoad.cpp +51 -0
  35. package/nitrogen/generated/android/RustCNetOnLoad.hpp +25 -0
  36. package/nitrogen/generated/android/c++/JFunc_void_double_std__shared_ptr_ArrayBuffer_.hpp +77 -0
  37. package/nitrogen/generated/android/c++/JHybridNetDriverSpec.cpp +74 -0
  38. package/nitrogen/generated/android/c++/JHybridNetDriverSpec.hpp +67 -0
  39. package/nitrogen/generated/android/c++/JHybridNetServerDriverSpec.cpp +99 -0
  40. package/nitrogen/generated/android/c++/JHybridNetServerDriverSpec.hpp +72 -0
  41. package/nitrogen/generated/android/c++/JHybridNetSocketDriverSpec.cpp +127 -0
  42. package/nitrogen/generated/android/c++/JHybridNetSocketDriverSpec.hpp +79 -0
  43. package/nitrogen/generated/android/c++/JNetConfig.hpp +57 -0
  44. package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/Func_void_double_std__shared_ptr_ArrayBuffer_.kt +80 -0
  45. package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HybridNetDriverSpec.kt +65 -0
  46. package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HybridNetServerDriverSpec.kt +92 -0
  47. package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HybridNetSocketDriverSpec.kt +122 -0
  48. package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/NetConfig.kt +38 -0
  49. package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/RustCNetOnLoad.kt +35 -0
  50. package/nitrogen/generated/ios/RustCNet+autolinking.rb +60 -0
  51. package/nitrogen/generated/ios/RustCNet-Swift-Cxx-Bridge.cpp +75 -0
  52. package/nitrogen/generated/ios/RustCNet-Swift-Cxx-Bridge.hpp +186 -0
  53. package/nitrogen/generated/ios/RustCNet-Swift-Cxx-Umbrella.hpp +60 -0
  54. package/nitrogen/generated/ios/RustCNetAutolinking.mm +35 -0
  55. package/nitrogen/generated/ios/RustCNetAutolinking.swift +12 -0
  56. package/nitrogen/generated/ios/c++/HybridNetDriverSpecSwift.cpp +11 -0
  57. package/nitrogen/generated/ios/c++/HybridNetDriverSpecSwift.hpp +100 -0
  58. package/nitrogen/generated/ios/c++/HybridNetServerDriverSpecSwift.cpp +11 -0
  59. package/nitrogen/generated/ios/c++/HybridNetServerDriverSpecSwift.hpp +117 -0
  60. package/nitrogen/generated/ios/c++/HybridNetSocketDriverSpecSwift.cpp +11 -0
  61. package/nitrogen/generated/ios/c++/HybridNetSocketDriverSpecSwift.hpp +163 -0
  62. package/nitrogen/generated/ios/swift/Func_void_double_std__shared_ptr_ArrayBuffer_.swift +47 -0
  63. package/nitrogen/generated/ios/swift/HybridNetDriverSpec.swift +58 -0
  64. package/nitrogen/generated/ios/swift/HybridNetDriverSpec_cxx.swift +167 -0
  65. package/nitrogen/generated/ios/swift/HybridNetServerDriverSpec.swift +61 -0
  66. package/nitrogen/generated/ios/swift/HybridNetServerDriverSpec_cxx.swift +217 -0
  67. package/nitrogen/generated/ios/swift/HybridNetSocketDriverSpec.swift +69 -0
  68. package/nitrogen/generated/ios/swift/HybridNetSocketDriverSpec_cxx.swift +288 -0
  69. package/nitrogen/generated/ios/swift/NetConfig.swift +36 -0
  70. package/nitrogen/generated/shared/c++/HybridNetDriverSpec.cpp +23 -0
  71. package/nitrogen/generated/shared/c++/HybridNetDriverSpec.hpp +74 -0
  72. package/nitrogen/generated/shared/c++/HybridNetServerDriverSpec.cpp +29 -0
  73. package/nitrogen/generated/shared/c++/HybridNetServerDriverSpec.hpp +72 -0
  74. package/nitrogen/generated/shared/c++/HybridNetSocketDriverSpec.cpp +36 -0
  75. package/nitrogen/generated/shared/c++/HybridNetSocketDriverSpec.hpp +78 -0
  76. package/nitrogen/generated/shared/c++/HybridNitroBufferSpec.cpp +32 -0
  77. package/nitrogen/generated/shared/c++/HybridNitroBufferSpec.hpp +74 -0
  78. package/nitrogen/generated/shared/c++/NetConfig.hpp +83 -0
  79. package/package.json +59 -0
  80. package/react-native-nitro-net.podspec +47 -0
  81. package/src/Driver.ts +4 -0
  82. package/src/Net.nitro.ts +85 -0
  83. package/src/index.ts +870 -0
@@ -0,0 +1,217 @@
1
+ ///
2
+ /// HybridNetServerDriverSpec_cxx.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * A class implementation that bridges HybridNetServerDriverSpec over to C++.
13
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
14
+ *
15
+ * Also, some Swift types need to be bridged with special handling:
16
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
17
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
18
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
19
+ */
20
+ open class HybridNetServerDriverSpec_cxx {
21
+ /**
22
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::net::bridge::swift`)
23
+ * from `RustCNet-Swift-Cxx-Bridge.hpp`.
24
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
25
+ */
26
+ public typealias bridge = margelo.nitro.net.bridge.swift
27
+
28
+ /**
29
+ * Holds an instance of the `HybridNetServerDriverSpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridNetServerDriverSpec
32
+
33
+ /**
34
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
35
+ */
36
+ private var __cxxPart: bridge.std__weak_ptr_HybridNetServerDriverSpec_
37
+
38
+ /**
39
+ * Create a new `HybridNetServerDriverSpec_cxx` that wraps the given `HybridNetServerDriverSpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridNetServerDriverSpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ /* no base class */
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridNetServerDriverSpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridNetServerDriverSpec() -> any HybridNetServerDriverSpec {
53
+ return __implementation
54
+ }
55
+
56
+ /**
57
+ * Casts this instance to a retained unsafe raw pointer.
58
+ * This acquires one additional strong reference on the object!
59
+ */
60
+ public func toUnsafe() -> UnsafeMutableRawPointer {
61
+ return Unmanaged.passRetained(self).toOpaque()
62
+ }
63
+
64
+ /**
65
+ * Casts an unsafe pointer to a `HybridNetServerDriverSpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridNetServerDriverSpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridNetServerDriverSpec_cxx {
70
+ return Unmanaged<HybridNetServerDriverSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
71
+ }
72
+
73
+ /**
74
+ * Gets (or creates) the C++ part of this Hybrid Object.
75
+ * The C++ part is a `std::shared_ptr<HybridNetServerDriverSpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridNetServerDriverSpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if Bool(fromCxx: cachedCxxPart) {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridNetServerDriverSpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridNetServerDriverSpec_(newCxxPart)
84
+ return newCxxPart
85
+ }
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Get the memory size of the Swift class (plus size of any other allocations)
92
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
93
+ */
94
+ @inline(__always)
95
+ public var memorySize: Int {
96
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
97
+ }
98
+
99
+ /**
100
+ * Call dispose() on the Swift class.
101
+ * This _may_ be called manually from JS.
102
+ */
103
+ @inline(__always)
104
+ public func dispose() {
105
+ self.__implementation.dispose()
106
+ }
107
+
108
+ /**
109
+ * Call toString() on the Swift class.
110
+ */
111
+ @inline(__always)
112
+ public func toString() -> String {
113
+ return self.__implementation.toString()
114
+ }
115
+
116
+ // Properties
117
+ public final var onEvent: bridge.Func_void_double_std__shared_ptr_ArrayBuffer_ {
118
+ @inline(__always)
119
+ get {
120
+ return { () -> bridge.Func_void_double_std__shared_ptr_ArrayBuffer_ in
121
+ let __closureWrapper = Func_void_double_std__shared_ptr_ArrayBuffer_(self.__implementation.onEvent)
122
+ return bridge.create_Func_void_double_std__shared_ptr_ArrayBuffer_(__closureWrapper.toUnsafe())
123
+ }()
124
+ }
125
+ @inline(__always)
126
+ set {
127
+ self.__implementation.onEvent = { () -> (Double, ArrayBuffer) -> Void in
128
+ let __wrappedFunction = bridge.wrap_Func_void_double_std__shared_ptr_ArrayBuffer_(newValue)
129
+ return { (__event: Double, __data: ArrayBuffer) -> Void in
130
+ __wrappedFunction.call(__event, __data)
131
+ }
132
+ }()
133
+ }
134
+ }
135
+
136
+ public final var maxConnections: Double {
137
+ @inline(__always)
138
+ get {
139
+ return self.__implementation.maxConnections
140
+ }
141
+ @inline(__always)
142
+ set {
143
+ self.__implementation.maxConnections = newValue
144
+ }
145
+ }
146
+
147
+ // Methods
148
+ @inline(__always)
149
+ public final func listen(port: Double, backlog: bridge.std__optional_double_, ipv6Only: bridge.std__optional_bool_, reusePort: bridge.std__optional_bool_) -> bridge.Result_void_ {
150
+ do {
151
+ try self.__implementation.listen(port: port, backlog: backlog.value, ipv6Only: { () -> Bool? in
152
+ if bridge.has_value_std__optional_bool_(ipv6Only) {
153
+ let __unwrapped = bridge.get_std__optional_bool_(ipv6Only)
154
+ return __unwrapped
155
+ } else {
156
+ return nil
157
+ }
158
+ }(), reusePort: { () -> Bool? in
159
+ if bridge.has_value_std__optional_bool_(reusePort) {
160
+ let __unwrapped = bridge.get_std__optional_bool_(reusePort)
161
+ return __unwrapped
162
+ } else {
163
+ return nil
164
+ }
165
+ }())
166
+ return bridge.create_Result_void_()
167
+ } catch (let __error) {
168
+ let __exceptionPtr = __error.toCpp()
169
+ return bridge.create_Result_void_(__exceptionPtr)
170
+ }
171
+ }
172
+
173
+ @inline(__always)
174
+ public final func listenUnix(path: std.string, backlog: bridge.std__optional_double_) -> bridge.Result_void_ {
175
+ do {
176
+ try self.__implementation.listenUnix(path: String(path), backlog: backlog.value)
177
+ return bridge.create_Result_void_()
178
+ } catch (let __error) {
179
+ let __exceptionPtr = __error.toCpp()
180
+ return bridge.create_Result_void_(__exceptionPtr)
181
+ }
182
+ }
183
+
184
+ @inline(__always)
185
+ public final func listenHandle(fd: Double, backlog: bridge.std__optional_double_) -> bridge.Result_void_ {
186
+ do {
187
+ try self.__implementation.listenHandle(fd: fd, backlog: backlog.value)
188
+ return bridge.create_Result_void_()
189
+ } catch (let __error) {
190
+ let __exceptionPtr = __error.toCpp()
191
+ return bridge.create_Result_void_(__exceptionPtr)
192
+ }
193
+ }
194
+
195
+ @inline(__always)
196
+ public final func getLocalAddress() -> bridge.Result_std__string_ {
197
+ do {
198
+ let __result = try self.__implementation.getLocalAddress()
199
+ let __resultCpp = std.string(__result)
200
+ return bridge.create_Result_std__string_(__resultCpp)
201
+ } catch (let __error) {
202
+ let __exceptionPtr = __error.toCpp()
203
+ return bridge.create_Result_std__string_(__exceptionPtr)
204
+ }
205
+ }
206
+
207
+ @inline(__always)
208
+ public final func close() -> bridge.Result_void_ {
209
+ do {
210
+ try self.__implementation.close()
211
+ return bridge.create_Result_void_()
212
+ } catch (let __error) {
213
+ let __exceptionPtr = __error.toCpp()
214
+ return bridge.create_Result_void_(__exceptionPtr)
215
+ }
216
+ }
217
+ }
@@ -0,0 +1,69 @@
1
+ ///
2
+ /// HybridNetSocketDriverSpec.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /// See ``HybridNetSocketDriverSpec``
12
+ public protocol HybridNetSocketDriverSpec_protocol: HybridObject {
13
+ // Properties
14
+ var id: Double { get }
15
+ var onEvent: (_ event: Double, _ data: ArrayBuffer) -> Void { get set }
16
+
17
+ // Methods
18
+ func connect(host: String, port: Double) throws -> Void
19
+ func connectUnix(path: String) throws -> Void
20
+ func write(data: ArrayBuffer) throws -> Void
21
+ func pause() throws -> Void
22
+ func resume() throws -> Void
23
+ func shutdown() throws -> Void
24
+ func setTimeout(timeout: Double) throws -> Void
25
+ func destroy() throws -> Void
26
+ func resetAndDestroy() throws -> Void
27
+ func setNoDelay(enable: Bool) throws -> Void
28
+ func setKeepAlive(enable: Bool, delay: Double) throws -> Void
29
+ func getLocalAddress() throws -> String
30
+ func getRemoteAddress() throws -> String
31
+ }
32
+
33
+ public extension HybridNetSocketDriverSpec_protocol {
34
+ /// Default implementation of ``HybridObject.toString``
35
+ func toString() -> String {
36
+ return "[HybridObject NetSocketDriver]"
37
+ }
38
+ }
39
+
40
+ /// See ``HybridNetSocketDriverSpec``
41
+ open class HybridNetSocketDriverSpec_base {
42
+ private weak var cxxWrapper: HybridNetSocketDriverSpec_cxx? = nil
43
+ public init() { }
44
+ public func getCxxWrapper() -> HybridNetSocketDriverSpec_cxx {
45
+ #if DEBUG
46
+ guard self is HybridNetSocketDriverSpec else {
47
+ fatalError("`self` is not a `HybridNetSocketDriverSpec`! Did you accidentally inherit from `HybridNetSocketDriverSpec_base` instead of `HybridNetSocketDriverSpec`?")
48
+ }
49
+ #endif
50
+ if let cxxWrapper = self.cxxWrapper {
51
+ return cxxWrapper
52
+ } else {
53
+ let cxxWrapper = HybridNetSocketDriverSpec_cxx(self as! HybridNetSocketDriverSpec)
54
+ self.cxxWrapper = cxxWrapper
55
+ return cxxWrapper
56
+ }
57
+ }
58
+ }
59
+
60
+ /**
61
+ * A Swift base-protocol representing the NetSocketDriver HybridObject.
62
+ * Implement this protocol to create Swift-based instances of NetSocketDriver.
63
+ * ```swift
64
+ * class HybridNetSocketDriver : HybridNetSocketDriverSpec {
65
+ * // ...
66
+ * }
67
+ * ```
68
+ */
69
+ public typealias HybridNetSocketDriverSpec = HybridNetSocketDriverSpec_protocol & HybridNetSocketDriverSpec_base
@@ -0,0 +1,288 @@
1
+ ///
2
+ /// HybridNetSocketDriverSpec_cxx.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * A class implementation that bridges HybridNetSocketDriverSpec over to C++.
13
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
14
+ *
15
+ * Also, some Swift types need to be bridged with special handling:
16
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
17
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
18
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
19
+ */
20
+ open class HybridNetSocketDriverSpec_cxx {
21
+ /**
22
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::net::bridge::swift`)
23
+ * from `RustCNet-Swift-Cxx-Bridge.hpp`.
24
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
25
+ */
26
+ public typealias bridge = margelo.nitro.net.bridge.swift
27
+
28
+ /**
29
+ * Holds an instance of the `HybridNetSocketDriverSpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridNetSocketDriverSpec
32
+
33
+ /**
34
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
35
+ */
36
+ private var __cxxPart: bridge.std__weak_ptr_HybridNetSocketDriverSpec_
37
+
38
+ /**
39
+ * Create a new `HybridNetSocketDriverSpec_cxx` that wraps the given `HybridNetSocketDriverSpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridNetSocketDriverSpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ /* no base class */
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridNetSocketDriverSpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridNetSocketDriverSpec() -> any HybridNetSocketDriverSpec {
53
+ return __implementation
54
+ }
55
+
56
+ /**
57
+ * Casts this instance to a retained unsafe raw pointer.
58
+ * This acquires one additional strong reference on the object!
59
+ */
60
+ public func toUnsafe() -> UnsafeMutableRawPointer {
61
+ return Unmanaged.passRetained(self).toOpaque()
62
+ }
63
+
64
+ /**
65
+ * Casts an unsafe pointer to a `HybridNetSocketDriverSpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridNetSocketDriverSpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridNetSocketDriverSpec_cxx {
70
+ return Unmanaged<HybridNetSocketDriverSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
71
+ }
72
+
73
+ /**
74
+ * Gets (or creates) the C++ part of this Hybrid Object.
75
+ * The C++ part is a `std::shared_ptr<HybridNetSocketDriverSpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridNetSocketDriverSpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if Bool(fromCxx: cachedCxxPart) {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridNetSocketDriverSpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridNetSocketDriverSpec_(newCxxPart)
84
+ return newCxxPart
85
+ }
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Get the memory size of the Swift class (plus size of any other allocations)
92
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
93
+ */
94
+ @inline(__always)
95
+ public var memorySize: Int {
96
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
97
+ }
98
+
99
+ /**
100
+ * Call dispose() on the Swift class.
101
+ * This _may_ be called manually from JS.
102
+ */
103
+ @inline(__always)
104
+ public func dispose() {
105
+ self.__implementation.dispose()
106
+ }
107
+
108
+ /**
109
+ * Call toString() on the Swift class.
110
+ */
111
+ @inline(__always)
112
+ public func toString() -> String {
113
+ return self.__implementation.toString()
114
+ }
115
+
116
+ // Properties
117
+ public final var id: Double {
118
+ @inline(__always)
119
+ get {
120
+ return self.__implementation.id
121
+ }
122
+ }
123
+
124
+ public final var onEvent: bridge.Func_void_double_std__shared_ptr_ArrayBuffer_ {
125
+ @inline(__always)
126
+ get {
127
+ return { () -> bridge.Func_void_double_std__shared_ptr_ArrayBuffer_ in
128
+ let __closureWrapper = Func_void_double_std__shared_ptr_ArrayBuffer_(self.__implementation.onEvent)
129
+ return bridge.create_Func_void_double_std__shared_ptr_ArrayBuffer_(__closureWrapper.toUnsafe())
130
+ }()
131
+ }
132
+ @inline(__always)
133
+ set {
134
+ self.__implementation.onEvent = { () -> (Double, ArrayBuffer) -> Void in
135
+ let __wrappedFunction = bridge.wrap_Func_void_double_std__shared_ptr_ArrayBuffer_(newValue)
136
+ return { (__event: Double, __data: ArrayBuffer) -> Void in
137
+ __wrappedFunction.call(__event, __data)
138
+ }
139
+ }()
140
+ }
141
+ }
142
+
143
+ // Methods
144
+ @inline(__always)
145
+ public final func connect(host: std.string, port: Double) -> bridge.Result_void_ {
146
+ do {
147
+ try self.__implementation.connect(host: String(host), port: port)
148
+ return bridge.create_Result_void_()
149
+ } catch (let __error) {
150
+ let __exceptionPtr = __error.toCpp()
151
+ return bridge.create_Result_void_(__exceptionPtr)
152
+ }
153
+ }
154
+
155
+ @inline(__always)
156
+ public final func connectUnix(path: std.string) -> bridge.Result_void_ {
157
+ do {
158
+ try self.__implementation.connectUnix(path: String(path))
159
+ return bridge.create_Result_void_()
160
+ } catch (let __error) {
161
+ let __exceptionPtr = __error.toCpp()
162
+ return bridge.create_Result_void_(__exceptionPtr)
163
+ }
164
+ }
165
+
166
+ @inline(__always)
167
+ public final func write(data: ArrayBuffer) -> bridge.Result_void_ {
168
+ do {
169
+ try self.__implementation.write(data: data)
170
+ return bridge.create_Result_void_()
171
+ } catch (let __error) {
172
+ let __exceptionPtr = __error.toCpp()
173
+ return bridge.create_Result_void_(__exceptionPtr)
174
+ }
175
+ }
176
+
177
+ @inline(__always)
178
+ public final func pause() -> bridge.Result_void_ {
179
+ do {
180
+ try self.__implementation.pause()
181
+ return bridge.create_Result_void_()
182
+ } catch (let __error) {
183
+ let __exceptionPtr = __error.toCpp()
184
+ return bridge.create_Result_void_(__exceptionPtr)
185
+ }
186
+ }
187
+
188
+ @inline(__always)
189
+ public final func resume() -> bridge.Result_void_ {
190
+ do {
191
+ try self.__implementation.resume()
192
+ return bridge.create_Result_void_()
193
+ } catch (let __error) {
194
+ let __exceptionPtr = __error.toCpp()
195
+ return bridge.create_Result_void_(__exceptionPtr)
196
+ }
197
+ }
198
+
199
+ @inline(__always)
200
+ public final func shutdown() -> bridge.Result_void_ {
201
+ do {
202
+ try self.__implementation.shutdown()
203
+ return bridge.create_Result_void_()
204
+ } catch (let __error) {
205
+ let __exceptionPtr = __error.toCpp()
206
+ return bridge.create_Result_void_(__exceptionPtr)
207
+ }
208
+ }
209
+
210
+ @inline(__always)
211
+ public final func setTimeout(timeout: Double) -> bridge.Result_void_ {
212
+ do {
213
+ try self.__implementation.setTimeout(timeout: timeout)
214
+ return bridge.create_Result_void_()
215
+ } catch (let __error) {
216
+ let __exceptionPtr = __error.toCpp()
217
+ return bridge.create_Result_void_(__exceptionPtr)
218
+ }
219
+ }
220
+
221
+ @inline(__always)
222
+ public final func destroy() -> bridge.Result_void_ {
223
+ do {
224
+ try self.__implementation.destroy()
225
+ return bridge.create_Result_void_()
226
+ } catch (let __error) {
227
+ let __exceptionPtr = __error.toCpp()
228
+ return bridge.create_Result_void_(__exceptionPtr)
229
+ }
230
+ }
231
+
232
+ @inline(__always)
233
+ public final func resetAndDestroy() -> bridge.Result_void_ {
234
+ do {
235
+ try self.__implementation.resetAndDestroy()
236
+ return bridge.create_Result_void_()
237
+ } catch (let __error) {
238
+ let __exceptionPtr = __error.toCpp()
239
+ return bridge.create_Result_void_(__exceptionPtr)
240
+ }
241
+ }
242
+
243
+ @inline(__always)
244
+ public final func setNoDelay(enable: Bool) -> bridge.Result_void_ {
245
+ do {
246
+ try self.__implementation.setNoDelay(enable: enable)
247
+ return bridge.create_Result_void_()
248
+ } catch (let __error) {
249
+ let __exceptionPtr = __error.toCpp()
250
+ return bridge.create_Result_void_(__exceptionPtr)
251
+ }
252
+ }
253
+
254
+ @inline(__always)
255
+ public final func setKeepAlive(enable: Bool, delay: Double) -> bridge.Result_void_ {
256
+ do {
257
+ try self.__implementation.setKeepAlive(enable: enable, delay: delay)
258
+ return bridge.create_Result_void_()
259
+ } catch (let __error) {
260
+ let __exceptionPtr = __error.toCpp()
261
+ return bridge.create_Result_void_(__exceptionPtr)
262
+ }
263
+ }
264
+
265
+ @inline(__always)
266
+ public final func getLocalAddress() -> bridge.Result_std__string_ {
267
+ do {
268
+ let __result = try self.__implementation.getLocalAddress()
269
+ let __resultCpp = std.string(__result)
270
+ return bridge.create_Result_std__string_(__resultCpp)
271
+ } catch (let __error) {
272
+ let __exceptionPtr = __error.toCpp()
273
+ return bridge.create_Result_std__string_(__exceptionPtr)
274
+ }
275
+ }
276
+
277
+ @inline(__always)
278
+ public final func getRemoteAddress() -> bridge.Result_std__string_ {
279
+ do {
280
+ let __result = try self.__implementation.getRemoteAddress()
281
+ let __resultCpp = std.string(__result)
282
+ return bridge.create_Result_std__string_(__resultCpp)
283
+ } catch (let __error) {
284
+ let __exceptionPtr = __error.toCpp()
285
+ return bridge.create_Result_std__string_(__exceptionPtr)
286
+ }
287
+ }
288
+ }
@@ -0,0 +1,36 @@
1
+ ///
2
+ /// NetConfig.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * Represents an instance of `NetConfig`, backed by a C++ struct.
13
+ */
14
+ public typealias NetConfig = margelo.nitro.net.NetConfig
15
+
16
+ public extension NetConfig {
17
+ private typealias bridge = margelo.nitro.net.bridge.swift
18
+
19
+ /**
20
+ * Create a new instance of `NetConfig`.
21
+ */
22
+ init(workerThreads: Double?) {
23
+ self.init({ () -> bridge.std__optional_double_ in
24
+ if let __unwrappedValue = workerThreads {
25
+ return bridge.create_std__optional_double_(__unwrappedValue)
26
+ } else {
27
+ return .init()
28
+ }
29
+ }())
30
+ }
31
+
32
+ @inline(__always)
33
+ var workerThreads: Double? {
34
+ return self.__workerThreads.value
35
+ }
36
+ }
@@ -0,0 +1,23 @@
1
+ ///
2
+ /// HybridNetDriverSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridNetDriverSpec.hpp"
9
+
10
+ namespace margelo::nitro::net {
11
+
12
+ void HybridNetDriverSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("createSocket", &HybridNetDriverSpec::createSocket);
18
+ prototype.registerHybridMethod("createServer", &HybridNetDriverSpec::createServer);
19
+ prototype.registerHybridMethod("initWithConfig", &HybridNetDriverSpec::initWithConfig);
20
+ });
21
+ }
22
+
23
+ } // namespace margelo::nitro::net