@@ -44,44 +44,6 @@ public class UserProperty: CStruct {
44
44
}
45
45
}
46
46
47
- extension Array where Element == UserProperty {
48
- func withCMqttUserProperties< Result> ( _ body: ( OpaquePointer ) throws -> Result ) rethrows -> Result {
49
- let array_list : UnsafeMutablePointer < aws_array_list > = allocator. allocate ( capacity: 1 )
50
- defer {
51
- aws_array_list_clean_up ( array_list)
52
- allocator. release ( array_list)
53
- }
54
- guard aws_array_list_init_dynamic (
55
- array_list,
56
- allocator. rawValue,
57
- count,
58
- MemoryLayout< aws_mqtt5_user_property> . size) == AWS_OP_SUCCESS else {
59
- fatalError ( " Unable to initialize array of user properties " )
60
- }
61
- forEach {
62
- $0. withCPointer {
63
- // `aws_array_list_push_back` will do a memory copy of $0 into array_list
64
- guard aws_array_list_push_back ( array_list, $0) == AWS_OP_SUCCESS else {
65
- fatalError ( " Unable to add user property " )
66
- }
67
- }
68
- }
69
- return try body ( OpaquePointer ( array_list. pointee. data) )
70
- }
71
- }
72
-
73
- /// Helper function to convert Swift [UserProperty]? into a native aws_mqtt5_user_property pointer
74
- func withOptionalUserPropertyArray< Result> (
75
- of array: Array < UserProperty > ? ,
76
- _ body: ( OpaquePointer ? ) throws -> Result ) rethrows -> Result {
77
- guard let _array = array else {
78
- return try body ( nil )
79
- }
80
- return try _array. withCMqttUserProperties { opaquePointer in
81
- return try body ( opaquePointer)
82
- }
83
- }
84
-
85
47
/// Convert a native aws_mqtt5_user_property pointer into a Swift [UserProperty]?
86
48
func convertOptionalUserProperties( count: size_t , userPropertiesPointer: UnsafePointer < aws_mqtt5_user_property > ? ) -> [ UserProperty ] ? {
87
49
@@ -367,32 +329,6 @@ public class Subscription: CStruct {
367
329
368
330
}
369
331
370
- extension Array where Element == Subscription {
371
- func withCSubscriptions< Result> ( _ body: ( OpaquePointer ) throws -> Result ) rethrows -> Result {
372
- let array_list : UnsafeMutablePointer < aws_array_list > = allocator. allocate ( capacity: 1 )
373
- defer {
374
- aws_array_list_clean_up ( array_list)
375
- allocator. release ( array_list)
376
- }
377
- guard aws_array_list_init_dynamic (
378
- array_list,
379
- allocator. rawValue,
380
- count,
381
- MemoryLayout< Element . RawType> . size) == AWS_OP_SUCCESS else {
382
- fatalError ( " Unable to initialize array of user properties " )
383
- }
384
- forEach {
385
- $0. withCPointer {
386
- // `aws_array_list_push_back` will do a memory copy of $0 into array_list
387
- guard aws_array_list_push_back ( array_list, $0) == AWS_OP_SUCCESS else {
388
- fatalError ( " Unable to add user property " )
389
- }
390
- }
391
- }
392
- return try body ( OpaquePointer ( array_list. pointee. data) )
393
- }
394
- }
395
-
396
332
/// Data model of an `MQTT5 SUBSCRIBE <https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161>`_ packet.
397
333
public class SubscribePacket : CStruct {
398
334
@@ -441,26 +377,26 @@ public class SubscribePacket: CStruct {
441
377
442
378
typealias RawType = aws_mqtt5_packet_subscribe_view
443
379
func withCStruct< Result> ( _ body: ( RawType ) -> Result ) -> Result {
444
- var raw_subscrbe_view = aws_mqtt5_packet_subscribe_view ( )
445
- return self . subscriptions. withCSubscriptions { subscriptionPointer in
446
- raw_subscrbe_view . subscriptions =
380
+ var raw_subscribe_view = aws_mqtt5_packet_subscribe_view ( )
381
+ return self . subscriptions. withAWSArrayList { subscriptionPointer in
382
+ raw_subscribe_view . subscriptions =
447
383
UnsafePointer < aws_mqtt5_subscription_view > ( subscriptionPointer)
448
- raw_subscrbe_view . subscription_count = self . subscriptions. count
384
+ raw_subscribe_view . subscription_count = self . subscriptions. count
449
385
450
386
return withOptionalUserPropertyArray (
451
387
of: userProperties) { userPropertyPointer in
452
388
453
389
if let userPropertyPointer,
454
390
let userPropertyCount = userProperties? . count {
455
- raw_subscrbe_view . user_property_count = userPropertyCount
456
- raw_subscrbe_view . user_properties =
391
+ raw_subscribe_view . user_property_count = userPropertyCount
392
+ raw_subscribe_view . user_properties =
457
393
UnsafePointer < aws_mqtt5_user_property > ( userPropertyPointer)
458
394
}
459
395
460
396
return withOptionalUnsafePointer (
461
- to: self . subscriptionIdentifier) { identiferPointer in
462
- raw_subscrbe_view . subscription_identifier = identiferPointer
463
- return body ( raw_subscrbe_view )
397
+ to: self . subscriptionIdentifier) { identifierPointer in
398
+ raw_subscribe_view . subscription_identifier = identifierPointer
399
+ return body ( raw_subscribe_view )
464
400
}
465
401
}
466
402
}
0 commit comments