-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/tracing
- Loading branch information
Showing
14 changed files
with
714 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// Copyright (c) 2023 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <zenoh@zettascale.tech> | ||
// | ||
|
||
package io.zenoh | ||
|
||
import io.zenoh.sample.Attachment | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.encodeToJsonElement | ||
import kotlin.io.path.Path | ||
|
||
@Serializable | ||
data class ConfigData( | ||
@SerialName("connect") var connect: Connect? = null, | ||
@SerialName("listen") var listen: Listen? = null, | ||
@SerialName("mode") var mode: String? = null, | ||
@SerialName("scouting") var scouting: Scouting? = null, | ||
) | ||
|
||
@Serializable | ||
data class Connect( | ||
@SerialName("endpoints") var endpoints: List<String> | ||
) | ||
|
||
@Serializable | ||
data class Listen( | ||
@SerialName("endpoints") var endpoints: List<String> | ||
) | ||
|
||
@Serializable | ||
data class Scouting( | ||
@SerialName("multicast") var multicast: Multicast, | ||
) | ||
|
||
@Serializable | ||
data class Multicast( | ||
@SerialName("enabled") var enabled: Boolean, | ||
) | ||
|
||
internal fun loadConfig( | ||
emptyArgs: Boolean, | ||
configFile: String?, | ||
connectEndpoints: List<String>, | ||
listenEndpoints: List<String>, | ||
noMulticastScouting: Boolean, | ||
mode: String? | ||
): Config { | ||
val config = if (emptyArgs) { | ||
Config.default() | ||
} else { | ||
configFile?.let { Config.from(Path(it)) } ?: run { | ||
val connect = Connect(connectEndpoints) | ||
val listen = Listen(listenEndpoints) | ||
val scouting = Scouting(Multicast(!noMulticastScouting)) | ||
val configData = ConfigData(connect, listen, mode, scouting) | ||
val jsonConfig = Json.encodeToJsonElement(configData) | ||
Config.from(jsonConfig) | ||
} | ||
} | ||
return config | ||
} | ||
|
||
internal fun decodeAttachment(attachment: String): Attachment { | ||
val pairs = attachment.split("&").map { it.split("=").let { (k, v) -> k.toByteArray() to v.toByteArray() } } | ||
return Attachment.Builder().addAll(pairs).res() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.