ZenohDotNet.Native
0.1.0
dotnet add package ZenohDotNet.Native --version 0.1.0
NuGet\Install-Package ZenohDotNet.Native -Version 0.1.0
<PackageReference Include="ZenohDotNet.Native" Version="0.1.0" />
<PackageVersion Include="ZenohDotNet.Native" Version="0.1.0" />
<PackageReference Include="ZenohDotNet.Native" />
paket add ZenohDotNet.Native --version 0.1.0
#r "nuget: ZenohDotNet.Native, 0.1.0"
#:package ZenohDotNet.Native@0.1.0
#addin nuget:?package=ZenohDotNet.Native&version=0.1.0
#tool nuget:?package=ZenohDotNet.Native&version=0.1.0
ZenohDotNet.Native
Low-level Zenoh FFI bindings for .NET with embedded runtime.
Overview
ZenohDotNet.Native provides P/Invoke bindings to the Zenoh C library, allowing .NET applications to use Zenoh's distributed messaging capabilities. The native Zenoh runtime is embedded in the NuGet package, so no separate installation is required.
Features
- Embedded Runtime: Zenoh C library is included in the package
- Cross-Platform: Supports Windows, Linux, and macOS on x64 and ARM64
- Mobile Support: Android (arm64-v8a, armeabi-v7a, x86_64) and iOS (arm64)
- Memory Safe: Proper IDisposable implementation for resource management
- .NET Standard 2.1: Compatible with .NET Core 3.0+, .NET 5+, and Unity 2021.2+
- Liveliness API: Monitor resource presence with liveliness tokens
- Attachments: Send key-value metadata alongside payloads
Supported Platforms
- Windows (x64, ARM64)
- Linux (x64, ARM64)
- macOS (x64, ARM64)
- Android (arm64-v8a, armeabi-v7a, x86_64)
- iOS (arm64)
Installation
dotnet add package ZenohDotNet.Native
Usage
Creating a Session
using ZenohDotNet.Native;
// Open a session with default configuration
using var session = new Session();
// Or with custom JSON configuration
var config = "{\"mode\":\"peer\"}";
using var session = new Session(config);
Publishing Data
using var session = new Session();
using var publisher = session.DeclarePublisher("demo/example/test");
// Publish a string
publisher.Put("Hello, Zenoh!");
// Publish bytes
byte[] data = { 1, 2, 3, 4 };
publisher.Put(data);
// Publish with encoding
publisher.Put(data, PayloadEncoding.ApplicationJson);
Publishing with Attachments
// Attachments are key-value metadata sent alongside the payload
var attachment = new Dictionary<string, string>
{
["sender"] = "device-001",
["priority"] = "high"
};
session.Put("demo/example/test", "Hello!", attachment);
Subscribing to Data
using var session = new Session();
using var subscriber = session.DeclareSubscriber("demo/example/**", sample =>
{
Console.WriteLine($"Received on {sample.KeyExpression}: {sample.GetPayloadAsString()}");
});
// Keep the application running to receive messages
Console.ReadLine();
Query/Queryable (Request-Response)
// Queryable (server)
using var queryable = session.DeclareQueryable("demo/query", query =>
{
Console.WriteLine($"Query received: {query.Selector}");
query.Reply("demo/query", "Response data");
});
// Query (client)
session.Get("demo/query", sample =>
{
Console.WriteLine($"Reply: {sample.GetPayloadAsString()}");
});
Liveliness API
Monitor resource presence using liveliness tokens:
// Declare a liveliness token (resource is "alive" while token exists)
using var token = session.DeclareLivelinessToken("my/resource/path");
// Subscribe to liveliness changes
using var liveSub = session.DeclareLivelinessSubscriber("my/**", (keyExpr, isAlive) =>
{
if (isAlive)
Console.WriteLine($"{keyExpr} is now alive");
else
Console.WriteLine($"{keyExpr} has died");
});
Delete
// Delete a key expression
session.Delete("demo/example/test");
API Reference
Session
Session()- Opens a session with default configurationSession(string configJson)- Opens a session with JSON configurationDeclarePublisher(string keyExpr)- Creates a publisherDeclarePublisher(string keyExpr, PublisherOptions options)- Creates a publisher with optionsDeclareSubscriber(string keyExpr, Action<Sample> callback)- Creates a subscriberDeclareQueryable(string keyExpr, Action<Query> callback)- Creates a queryableDeclareQuerier(string keyExpr)- Creates a querier for repeated queriesGet(string selector, Action<Sample> callback)- Performs a queryPut(string keyExpr, byte[] data)- Direct put without publisherPut(string keyExpr, byte[] data, IDictionary<string, string> attachment)- Put with attachmentDelete(string keyExpr)- Delete a key expressionDeclareLivelinessToken(string keyExpr)- Declare a liveliness tokenDeclareLivelinessSubscriber(string keyExpr, Action<string, bool> callback)- Subscribe to liveliness changesGetZenohId()- Gets the session's Zenoh ID
Publisher
Put(byte[] data)- Publishes binary dataPut(string value)- Publishes a UTF-8 stringPut(byte[] data, PayloadEncoding encoding)- Publishes with encodingKeyExpression- Gets the key expression
Subscriber
- Automatically receives data via callback
- Callback receives
Sampleobjects
Sample
KeyExpression- The key expression of the samplePayload- Raw byte array payloadKind- Sample kind (Put or Delete)Encoding- Payload encodingTimestamp- Optional timestampGetPayloadAsString()- Converts payload to UTF-8 string
Query
Selector- The query selectorPayload- Optional query payloadReply(string keyExpr, byte[] data)- Reply to the queryReply(string keyExpr, string value)- Reply with a string
LivelinessToken
KeyExpression- The token's key expression- Disposing the token signals the resource is no longer alive
LivelinessSubscriber
- Receives
(string keyExpr, bool isAlive)callbacks isAlive = truewhen a token is declaredisAlive = falsewhen a token is dropped
Building from Source
See the main repository README for build instructions.
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ZenohDotNet.Native:
| Package | Downloads |
|---|---|
|
ZenohDotNet.Client
MIT-licensed high-level async Zenoh client for .NET 8.0+. Depends on ZenohDotNet.Native, which bundles Zenoh native binaries licensed under Apache-2.0. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 56 | 2/2/2026 |