Skip to content

Implementation of Encoder and Decoder Protocols targeting libxpc

License

Notifications You must be signed in to change notification settings

open-imcore/CodableXPC

 
 

Repository files navigation

CodableXPC

Build Status

This provides an Encoder and Decoder protocol implementation that should allow users to target libxpc. This is only available on macOS as libxpc is not supported on other platforms.

Usage

The usage is very simple, your types should conform to Codable, Decodable, or Encodable depending the semantics you want. Then you should use the provided XPCEncoder.encode and XPCDecoder.decode static functions to marshal and unmarshal from and to native xpc_object_t respectively. A short minimal example is provided below.

struct TestStruct {
    let opinion = "XPC is awesome!"
}

let value = TestStruct()
let payload = try! XPCEncoder.encode(value)
let decoded = try! XPCDecoder.decode(payload)

assert(value == decoded)

However, it is worth noting that this API is not sufficient to write correct XPC code in Swift. You will need to provide a correct xpc_main and manage your transactions using the existing abstractions provided by the SDK. Specifically, this API does not support reply dictionaries.

Again, this library is only meant to be used as a way to reduce boilerplate around writing marshalling code for Swift type and cannot be used without the usual libxpc APIs provided by the macOS SDK.

Dependencies and Distribution

This package is distributed solely using SwiftPM, I will ignore any requests to distribute using CocoaPods or Carthage. As far as I know this has no dependencies apart from the standard macOS SDK, but if you find something let me know.

About

Implementation of Encoder and Decoder Protocols targeting libxpc

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%