asterism-zenoh 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,105 @@
1
+ # The values the C extension hands out (samples, replies, events), and the
2
+ # Ruby half of scouting. Plain immutable Data objects: they work with
3
+ # pattern matching (case sample in {kind: :delete, key:}).
4
+ module Asterism
5
+ module Zenoh
6
+ # A received sample, from Subscriber#each_sample and
7
+ # AdvancedSubscriber#each_sample. payload and attachment are binary
8
+ # Strings (attachment nil when there was none). kind is :put or
9
+ # :delete; encoding a String such as "application/json"; timestamp an
10
+ # Asterism::Zenoh::Timestamp or nil (zenoh only stamps samples when the
11
+ # sender or a router does); priority, congestion_control and
12
+ # reliability Symbols; source_zid the sender's Zenoh ID when it said.
13
+ # Sample.new(key, payload, attachment) still works (the other fields
14
+ # have defaults).
15
+ Sample = Data.define(:key, :payload, :attachment, :kind, :encoding, :timestamp, :priority,
16
+ :congestion_control, :express, :reliability, :source_zid) do
17
+ def initialize(key:, payload:, attachment: nil, kind: :put, encoding: nil, timestamp: nil, priority: nil,
18
+ congestion_control: nil, express: false, reliability: nil, source_zid: nil)
19
+ super
20
+ end
21
+
22
+ # The payload as UTF-8.
23
+ def text
24
+ payload.dup.force_encoding(Encoding::UTF_8)
25
+ end
26
+
27
+ def put? = kind == :put
28
+ def delete? = kind == :delete
29
+
30
+ def to_s
31
+ "#{key}: #{payload}"
32
+ end
33
+ end
34
+
35
+ # A reply to a get, from Get#each_result: an answer (error false) with
36
+ # the fields of a sample, or an error reply (error true: payload and
37
+ # encoding of the error, key nil). replier_zid: who answered, when known.
38
+ # Reply.new(key, payload, attachment) still works.
39
+ Reply = Data.define(:key, :payload, :attachment, :kind, :encoding, :timestamp, :error, :replier_zid) do
40
+ def initialize(key:, payload:, attachment: nil, kind: :put, encoding: nil, timestamp: nil, error: false,
41
+ replier_zid: nil)
42
+ super
43
+ end
44
+
45
+ def text
46
+ payload.dup.force_encoding(Encoding::UTF_8)
47
+ end
48
+
49
+ def ok? = !error
50
+ def error? = error
51
+
52
+ def to_s
53
+ error ? "error: #{payload}" : "#{key}: #{payload}"
54
+ end
55
+ end
56
+
57
+ # An answer to scouting: a router or peer (whatami :router / :peer /
58
+ # :client), its Zenoh ID and the locators it can be reached at.
59
+ Hello = Data.define(:zid, :whatami, :locators)
60
+
61
+ # A connection to another peer or router (Session#transports).
62
+ Transport = Data.define(:zid, :whatami, :qos, :multicast)
63
+
64
+ # A transport that appeared (kind :added) or went (:removed), from
65
+ # Session#transport_events.
66
+ TransportEvent = Data.define(:kind, :zid, :whatami, :qos, :multicast) do
67
+ def added? = kind == :added
68
+ def removed? = kind == :removed
69
+ end
70
+
71
+ # A link (one connection of a transport; Session#links).
72
+ Link = Data.define(:zid, :src, :dst, :mtu, :streamed, :reliability, :interfaces, :group, :auth_identifier)
73
+
74
+ # A link that opened (kind :added) or closed (:removed), from
75
+ # Session#link_events.
76
+ LinkEvent = Data.define(:kind, :zid, :src, :dst, :mtu, :streamed, :reliability, :interfaces, :group,
77
+ :auth_identifier) do
78
+ def added? = kind == :added
79
+ def removed? = kind == :removed
80
+ end
81
+
82
+ # Samples that a publisher sent and that never arrived
83
+ # (AdvancedSubscriber#miss_listener): count of them, from the publisher
84
+ # source_zid / source_eid.
85
+ Miss = Data.define(:source_zid, :source_eid, :count)
86
+
87
+ SCOUT_WHAT = { router: 1, peer: 2, client: 4 }.freeze
88
+
89
+ # Looks for routers and / or peers by multicast scouting for timeout
90
+ # seconds (or timeout_ms milliseconds) and returns what answered, as an
91
+ # Array of Hello. what: :router, :peer, :client, an Array of them, or
92
+ # :all. config: a Hash of zenoh configuration keys, as for
93
+ # Session.open (e.g. {"scouting/multicast/interface" => "eth0"}).
94
+ # Multicast must be allowed on the network (it often is not in
95
+ # containers and VPNs).
96
+ def self.scout(what: %i[router peer], timeout: 1.0, timeout_ms: nil, config: nil)
97
+ kinds = what == :all ? SCOUT_WHAT.keys : Array(what)
98
+ mask = kinds.sum do |k|
99
+ SCOUT_WHAT.fetch(k.to_sym) { raise ArgumentError, "what must be :router, :peer, :client or :all" }
100
+ end
101
+ ms = timeout_ms || (timeout * 1000).round
102
+ _scout(mask, ms, config)
103
+ end
104
+ end
105
+ end
@@ -1,6 +1,6 @@
1
1
  module Asterism
2
2
  module Zenoh
3
3
  # The gem's version.
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
@@ -1,6 +1,10 @@
1
1
  # Asterism::Zenoh for CRuby: the Zenoh binding of Asterism, over zenoh-c.
2
2
  # The same Ruby API as the mruby / PicoRuby gem (picoruby-asterism-zenoh):
3
3
  # see README.md. Receiving is polled (each_pending / each_reply) from the
4
- # application's own thread; nothing calls into Ruby behind its back.
4
+ # application's own thread; nothing calls into Ruby behind its back. The
5
+ # calls added in 0.3.0 (configuration, publishers, queriers, the advanced
6
+ # publisher / subscriber, events, key expressions, timestamps) are CRuby
7
+ # only: see docs/feature_coverage.md.
5
8
  require_relative "zenoh/version"
6
9
  require_relative "asterism_zenoh"
10
+ require_relative "zenoh/values"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asterism-zenoh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuhiko Kageyama
@@ -11,9 +11,11 @@ cert_chain: []
11
11
  date: 2026-10-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Sessions, put / subscribe, get / queryable, liveliness and attachments,
14
- received by polling. The same Ruby API as Asterism's mruby / PicoRuby binding. The
15
- C extension is compiled at install time against the official prebuilt zenoh-c release
16
- for the machine, downloaded and checked against a pinned sha256.
14
+ received by polling. The same Ruby API as Asterism's mruby / PicoRuby binding, plus
15
+ (CRuby only) configuration and TLS, scouting, publishers, queriers, the advanced
16
+ publisher / subscriber, events, key expressions and timestamps. The C extension
17
+ is compiled at install time against the official prebuilt zenoh-c release for the
18
+ machine, downloaded and checked against a pinned sha256.
17
19
  email:
18
20
  executables: []
19
21
  extensions:
@@ -23,11 +25,13 @@ files:
23
25
  - LICENSE
24
26
  - README.md
25
27
  - ZENOH_C_PIN
28
+ - docs/feature_coverage.md
26
29
  - ext/asterism_zenoh/extconf.rb
27
30
  - ext/asterism_zenoh/zenoh.c
28
31
  - ext/asterism_zenoh/zenoh_c.rb
29
32
  - lib/asterism/zenoh.rb
30
33
  - lib/asterism/zenoh/global.rb
34
+ - lib/asterism/zenoh/values.rb
31
35
  - lib/asterism/zenoh/version.rb
32
36
  - licenses/zenoh-c/LICENSE-APACHE
33
37
  - licenses/zenoh-c/NOTICE.md