mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-04 06:53:06 +00:00
fix: pubsub topic is a string
This commit is contained in:
parent
c04eb6b7ee
commit
ba706164b1
2
.github/workflows/codecov.yml
vendored
2
.github/workflows/codecov.yml
vendored
@ -20,7 +20,7 @@ jobs:
|
|||||||
run: git submodule update --init --recursive
|
run: git submodule update --init --recursive
|
||||||
- uses: actions/setup-go@v3 # we need go to build go-waku
|
- uses: actions/setup-go@v3 # we need go to build go-waku
|
||||||
with:
|
with:
|
||||||
go-version: '1.19'
|
go-version: '1.20'
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
|
|||||||
6
.github/workflows/main.yml
vendored
6
.github/workflows/main.yml
vendored
@ -29,7 +29,7 @@ jobs:
|
|||||||
run: git submodule update --init --recursive
|
run: git submodule update --init --recursive
|
||||||
- uses: actions/setup-go@v3 # we need go to build go-waku
|
- uses: actions/setup-go@v3 # we need go to build go-waku
|
||||||
with:
|
with:
|
||||||
go-version: '1.19'
|
go-version: '1.20'
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
@ -61,7 +61,7 @@ jobs:
|
|||||||
run: git submodule update --init --recursive
|
run: git submodule update --init --recursive
|
||||||
- uses: actions/setup-go@v3 # we need go to build go-waku
|
- uses: actions/setup-go@v3 # we need go to build go-waku
|
||||||
with:
|
with:
|
||||||
go-version: '1.19'
|
go-version: '1.20'
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
@ -88,7 +88,7 @@ jobs:
|
|||||||
run: git submodule update --init --recursive
|
run: git submodule update --init --recursive
|
||||||
- uses: actions/setup-go@v3 # we need go to build go-waku
|
- uses: actions/setup-go@v3 # we need go to build go-waku
|
||||||
with:
|
with:
|
||||||
go-version: '1.19'
|
go-version: '1.20'
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
|
|||||||
4
examples/Cargo.lock
generated
4
examples/Cargo.lock
generated
@ -1497,7 +1497,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "waku-bindings"
|
name = "waku-bindings"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes-gcm",
|
"aes-gcm",
|
||||||
"base64 0.21.0",
|
"base64 0.21.0",
|
||||||
@ -1518,7 +1518,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "waku-sys"
|
name = "waku-sys"
|
||||||
version = "0.3.0"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -20,6 +20,8 @@ pub type WakuMessageVersion = usize;
|
|||||||
pub type PeerId = String;
|
pub type PeerId = String;
|
||||||
/// Waku message id, hex encoded sha256 digest of the message
|
/// Waku message id, hex encoded sha256 digest of the message
|
||||||
pub type MessageId = String;
|
pub type MessageId = String;
|
||||||
|
/// Waku pubsub topic
|
||||||
|
pub type WakuPubSubTopic = String;
|
||||||
|
|
||||||
/// Protocol identifiers
|
/// Protocol identifiers
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
@ -515,75 +517,6 @@ impl<'de> Deserialize<'de> for WakuContentTopic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A waku pubsub topic in the form of `/waku/v2/{topic_name}/{encoding}`
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
||||||
pub struct WakuPubSubTopic {
|
|
||||||
pub topic_name: Cow<'static, str>,
|
|
||||||
pub encoding: Encoding,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WakuPubSubTopic {
|
|
||||||
pub const fn new(topic_name: &'static str, encoding: Encoding) -> Self {
|
|
||||||
Self {
|
|
||||||
topic_name: Cow::Borrowed(topic_name),
|
|
||||||
encoding,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_topic_name(topic_name: String, encoding: Encoding) -> Self {
|
|
||||||
Self {
|
|
||||||
topic_name: Cow::Owned(topic_name),
|
|
||||||
encoding,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for WakuPubSubTopic {
|
|
||||||
type Err = String;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
|
||||||
if let Ok((topic_name, encoding)) = scanf!(s, "/waku/2/{}/{:/.+?/}", String, Encoding) {
|
|
||||||
Ok(WakuPubSubTopic {
|
|
||||||
topic_name: Cow::Owned(topic_name),
|
|
||||||
encoding,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Err(
|
|
||||||
format!(
|
|
||||||
"Wrong pub-sub topic format. Should be `/waku/2/{{topic-name}}/{{encoding}}`. Got: {s}"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for WakuPubSubTopic {
|
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "/waku/2/{}/{}", self.topic_name, self.encoding)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Serialize for WakuPubSubTopic {
|
|
||||||
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
self.to_string().serialize(serializer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for WakuPubSubTopic {
|
|
||||||
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let as_string: String = String::deserialize(deserializer)?;
|
|
||||||
as_string
|
|
||||||
.parse::<WakuPubSubTopic>()
|
|
||||||
.map_err(D::Error::custom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod base64_serde {
|
mod base64_serde {
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use serde::de::Error;
|
use serde::de::Error;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user