forked from trilemma-dev/SecureXPC
-
Notifications
You must be signed in to change notification settings - Fork 0
Optimize Array and Data encoding for XPC #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
89afaa1
introduce XPCCodable protocols family; adapt Array and Data to the pr…
r-fogash b2505f7
remove unused data transform
r-fogash c94cf66
remove comment from array decoding tests
r-fogash f7a475a
remove dictionary decoding comment
r-fogash 88f7286
remove coding keys from xcp coders methods
r-fogash ec4fb7a
change macos version to 10.10
r-fogash 9d60459
support of singlevaluecontainer for rawxpccoders
r-fogash 203f416
add comments for the testing structures
r-fogash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
Sources/SecureXPC/Codable Types/XPCRawCodable/Array+XPCRawCodable.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // | ||
| // Array+XPCRawCodable.swift | ||
| // SecureXPC | ||
| // | ||
| // Created by Robert Fogash on 27.02.2026. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| extension Array: XPCRawEncodable where Array.Element: Trivial { | ||
|
|
||
| func xpcRawValue() -> xpc_object_t? { | ||
| self.withUnsafePointer { | ||
| xpc_data_create($0, self.elementCount * type(of: self).elementStride) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension Array: XPCRawDecodable where Array.Element: Trivial { | ||
|
|
||
| init?(xpcRawValue: xpc_object_t) { | ||
| guard xpc_get_type(xpcRawValue) == XPC_TYPE_DATA, | ||
| let dataPointer = xpc_data_get_bytes_ptr(xpcRawValue) | ||
| else { | ||
| return nil | ||
| } | ||
| self = Array(pointer: dataPointer, count: xpc_data_get_length(xpcRawValue) / MemoryLayout<Element>.size) | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
Sources/SecureXPC/Codable Types/XPCRawCodable/Data+XPCRawCodable.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // | ||
| // File.swift | ||
| // SecureXPC | ||
| // | ||
| // Created by Robert Fogash on 27.02.2026. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| extension Data: XPCRawEncodable { | ||
|
|
||
| func xpcRawValue() -> xpc_object_t? { | ||
| withUnsafeBytes { (buffer: UnsafeRawBufferPointer) -> xpc_object_t? in | ||
| guard let baseAddress = buffer.baseAddress?.assumingMemoryBound(to: UInt8.self) | ||
| else { | ||
| return nil | ||
| } | ||
| return xpc_data_create(baseAddress, buffer.count) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension Data: XPCRawDecodable { | ||
|
|
||
| init?(xpcRawValue: xpc_object_t) { | ||
| guard xpc_get_type(xpcRawValue) == XPC_TYPE_DATA, | ||
| let dataPointer = xpc_data_get_bytes_ptr(xpcRawValue) | ||
| else { | ||
| return nil | ||
| } | ||
| self.init(bytes: dataPointer, count: xpc_data_get_length(xpcRawValue)) | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
Sources/SecureXPC/Codable Types/XPCRawCodable/XPCRawCodable.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // | ||
| // File.swift | ||
| // SecureXPC | ||
| // | ||
| // Created by Robert Fogash on 27.02.2026. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| protocol XPCRawEncodable { | ||
|
|
||
| func xpcRawValue() -> xpc_object_t? | ||
| } | ||
|
|
||
| protocol XPCRawDecodable { | ||
|
|
||
| init?(xpcRawValue: xpc_object_t) | ||
| } | ||
|
|
||
| typealias XPCRawCodable = XPCRawDecodable & XPCRawEncodable | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.