Documentation
¶
Overview ¶
Package dds defines the Go interface for Data Distribution Service (DDS) publish/subscribe operations.
The interface is intentionally narrow: it covers the pub/sub primitives needed for vehicle-signal transport (e.g. VISS/VISSR) and nothing more.
Choose an implementation by importing one of the sub-packages and calling its New function:
import "github.com/SoundMatt/go-DDS/mock" // in-process, no CGo import "github.com/SoundMatt/go-DDS/cyclone" // CycloneDDS via CGo import "github.com/SoundMatt/go-DDS/rtps" // pure-Go RTPS/UDP
All packages expose a New(Domain) (Participant, error) constructor that satisfies this package's Participant interface.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultQoS = QoS{ Reliability: BestEffort, Durability: Volatile, HistoryDepth: 1, }
DefaultQoS is BestEffort + Volatile with implementation-default history. Appropriate for live vehicle telemetry and VISS request/response traffic.
var ReliableQoS = QoS{ Reliability: Reliable, Durability: TransientLocal, HistoryDepth: 1, }
ReliableQoS is Reliable + TransientLocal. Use for actuator commands and any topic where a late-joining subscriber must receive the current value.
Functions ¶
This section is empty.
Types ¶
type Domain ¶
type Domain int
Domain is a DDS domain identifier (0–232 inclusive per the DDS spec). Participants on the same domain and network segment discover each other automatically without a broker.
type DurabilityKind ¶
type DurabilityKind int
DurabilityKind controls whether late-joining subscribers receive historical samples that were published before they joined.
const ( // Volatile discards samples as soon as they are delivered. Appropriate // for live telemetry that has no meaning outside its observation window. Volatile DurabilityKind = iota // TransientLocal retains the last N samples (per history depth) so that // late joiners receive current state on subscription. TransientLocal )
type Participant ¶
type Participant interface {
// NewPublisher creates a writer for the named topic using the given QoS.
// The topic is created if it does not already exist in this domain.
NewPublisher(topic string, qos QoS) (Publisher, error)
// NewSubscriber creates a reader for the named topic using the given QoS.
// Samples arrive on the channel returned by Subscriber.C().
NewSubscriber(topic string, qos QoS) (Subscriber, error)
// Close releases all DDS resources held by this participant, including
// all publishers and subscribers it created. Calling Close more than
// once is a no-op.
Close() error
}
Participant is the DDS domain participant — the root factory for all DDS entities. Create one per process per domain. A Participant is safe for concurrent use from multiple goroutines.
type Publisher ¶
type Publisher interface {
// Write publishes payload to the topic. The call returns after the
// sample has been handed to the DDS transport layer; it does not wait
// for acknowledgement from subscribers (even under Reliable QoS).
Write(payload []byte) error
// Close releases the publisher. After Close, Write returns an error.
Close() error
}
Publisher writes samples to a single DDS topic. A Publisher is safe for concurrent use from multiple goroutines.
type QoS ¶
type QoS struct {
Reliability ReliabilityKind
Durability DurabilityKind
HistoryDepth int // 0 means implementation default (typically 1)
}
QoS bundles the policies that govern a single publisher or subscriber endpoint.
type ReliabilityKind ¶
type ReliabilityKind int
ReliabilityKind controls delivery guarantees for a topic endpoint.
const ( // BestEffort delivers samples without retransmission. Suitable for // high-frequency sensor data where occasional loss is acceptable. BestEffort ReliabilityKind = iota // Reliable retransmits lost samples until acknowledged. Required for // command/control and actuator writes. Reliable )
type Sample ¶
Sample is a single data sample delivered to a Subscriber. Payload is the raw bytes written by the corresponding Publisher; Topic is the DDS topic name on which the sample arrived.
type Subscriber ¶
type Subscriber interface {
// C returns the channel on which inbound samples are delivered.
// The channel is closed when Close is called.
C() <-chan Sample
// Close stops sample delivery and closes the channel returned by C.
// Calling Close more than once is a no-op.
Close() error
}
Subscriber reads samples from a single DDS topic as a Go channel. A Subscriber is safe for concurrent use from multiple goroutines.
type WaitSet ¶
type WaitSet struct {
// contains filtered or unexported fields
}
WaitSet multiplexes over a set of subscribers, blocking until any one of them delivers a sample. It is the Go-idiomatic replacement for the polling loop pattern common in DDS applications.
A WaitSet is safe for concurrent use — multiple goroutines may call Wait simultaneously and each will receive a distinct sample.
func NewWaitSet ¶
func NewWaitSet(subs ...Subscriber) *WaitSet
NewWaitSet creates a WaitSet that monitors the given subscribers. The set is fixed at construction; add/remove by creating a new WaitSet.
Example ¶
ExampleNewWaitSet demonstrates multiplexing over two subscribers without a polling loop. The WaitSet blocks until any attached subscriber delivers a sample, then returns it together with the subscriber it arrived on.
package main
import (
"context"
"fmt"
"time"
dds "github.com/SoundMatt/go-DDS"
"github.com/SoundMatt/go-DDS/mock"
)
func main() {
p, _ := mock.New(dds.Domain(0))
defer p.Close()
subTemp, _ := p.NewSubscriber("sensors/temp", dds.DefaultQoS)
subSpeed, _ := p.NewSubscriber("vehicle/speed", dds.DefaultQoS)
defer subTemp.Close()
defer subSpeed.Close()
pubTemp, _ := p.NewPublisher("sensors/temp", dds.DefaultQoS)
defer pubTemp.Close()
_ = pubTemp.Write([]byte("21.5"))
ws := dds.NewWaitSet(subTemp, subSpeed)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
sample, sub, err := ws.Wait(ctx)
if err != nil {
fmt.Println("error:", err)
return
}
switch sub {
case subTemp:
fmt.Println("temp:", string(sample.Payload))
case subSpeed:
fmt.Println("speed:", string(sample.Payload))
}
}
Output: temp: 21.5
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cyclone provides a CycloneDDS-backed implementation of the dds interfaces via CGo.
|
Package cyclone provides a CycloneDDS-backed implementation of the dds interfaces via CGo. |
|
Package interop contains RTPS wire-compatibility tests that require a live CycloneDDS peer.
|
Package interop contains RTPS wire-compatibility tests that require a live CycloneDDS peer. |
|
Package mock provides an in-process, CGo-free implementation of the dds interfaces.
|
Package mock provides an in-process, CGo-free implementation of the dds interfaces. |
|
Package rtps provides a pure-Go RTPS/UDP implementation of the dds interfaces.
|
Package rtps provides a pure-Go RTPS/UDP implementation of the dds interfaces. |
|
Package security provides pluggable transport-security for go-DDS.
|
Package security provides pluggable transport-security for go-DDS. |