Skip to content

literally-anything/DDSKit

Repository files navigation

DDSKit

License GitHub Release Date

DDSKit is an inter-process and inter-device communication library built using FastDDS. DDSKit aims provide a simpler and easier-to-use API in Swift, including asynchronous operations using await and a request-reply model, while still remaining performant. DDSKit enables FastDDS's datasharing, intra-process, and zero-copy delivery methods for faster communication between threads or processes on the same machine.

This does actually run on Linux, even though the SPI says it won't. I haven't gotten around to making a docker container that has FastDDS installed, so it will fail to build on the SPI's Linux builds.

Some use cases for this library are:

  • Robotics/Interfacing with ROS2
  • Distributed systems
  • High data rate communitcation

Supported Platforms

Platform Support
Linux Supported*1*2
MacOS Supported*3*2
Other Apple OSs Supported*3*2
Windows Absolutely no clue, but it might work*2

Example

The following code publishes a message on a topic

import DDSKit

DDSParticipant.setIntraProcessDelivery(enabled: false)  // Without this fastdds crashes. I don't know why yet; I haven't had a change to check.

@DDSMessage
struct HelloWorld {
    var index: Int
    var message: String
}

let participant = DDSParticipant()
let publisher = participant.publish(to: "hello/world", type: HelloWorld.self)
publisher.publish(
    HelloWorld(index: 27, message: "Hello World)
)

To recieve this message, the following code subscribes to the topic and prints each message as it arrives

import DDSKit

let participant = DDSParticipant()
let subscriber = participant.subscribe(to: "hello/world", type: HelloWorld.self)
for await message in subscriber.messages {
    print(message)
}

Using DDSKit

If you are on Linux, you need to install FastDDS as well. Apple platforms default to using a prebuilt version. DDSKit is available as a Swift Package Manager package. To use it in a package, add the following dependency in your Package.swift

.package(
    url: "https://github.com/literally-anything/DDSKit.git",
    from: "1.0.0"
)

Replace "tag" with any release number: tags. To use the DDSKit library, add

.product(name: "DDSKit", package: "DDSKit")

to your target's dependencies.

Footnotes

  1. FastDDS must be installed and it needs to findable using pkg-config for it to work with no exta setup.

  2. Needs tests 2 3 4

  3. Prebuilt dylibs of fastdds and fastcdr are used by default on Apple platforms. On MacOS, this can be disabled by disabling the DarwinDDSPrebuild package trait. 2