Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ mod ustatus;
pub use ustatus::{UCode, UStatus};

mod utransport;
pub use utransport::UTransport;

pub use utransport::{ComparableListener, UListener, UTransport};
mod uuid;
pub use uuid::{UUIDBuilder, UUID};

Expand All @@ -95,6 +94,7 @@ pub use up_core_api::utwin;
// cloudevent-proto, generated and augmented types
#[cfg(feature = "cloudevents")]
pub mod cloudevents;

#[cfg(feature = "cloudevents")]
mod proto_cloudevents {
include!(concat!(env!("OUT_DIR"), "/cloudevents/mod.rs"));
Expand Down
11 changes: 11 additions & 0 deletions src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

use std::hash::{Hash, Hasher};
use std::io::Write;
use std::str::FromStr;

Expand Down Expand Up @@ -549,6 +550,16 @@ impl TryFrom<Vec<u8>> for UUri {
}
}

impl Hash for UUri {
fn hash<H: Hasher>(&self, state: &mut H) {
self.authority.hash(state);
self.entity.hash(state);
self.resource.hash(state);
}
}

impl Eq for UUri {}

impl UUri {
/// Builds a fully resolved `UUri` from the serialized long format and the serialized micro format.
///
Expand Down
21 changes: 21 additions & 0 deletions src/uri/uauthority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
********************************************************************************/

use bytes::BufMut;
use std::hash::{Hash, Hasher};

pub use crate::up_core_api::uri::{uauthority::Number, UAuthority};
use crate::uri::UUriError;
Expand All @@ -21,6 +22,26 @@ const REMOTE_IPV6_BYTES: usize = 16;
const REMOTE_ID_MINIMUM_BYTES: usize = 1;
const REMOTE_ID_MAXIMUM_BYTES: usize = 255;

impl Hash for UAuthority {
fn hash<H: Hasher>(&self, state: &mut H) {
self.number.hash(state);
}
}

impl Eq for UAuthority {}

impl Hash for Number {
fn hash<H: Hasher>(&self, state: &mut H) {
std::mem::discriminant(self).hash(state);
match self {
Number::Ip(ip) => ip.hash(state),
Number::Id(id) => id.hash(state),
}
}
}

impl Eq for Number {}

/// uProtocol defines a [Micro-URI format](https://github.com/eclipse-uprotocol/up-spec/blob/main/basics/uri.adoc#42-micro-uris), which contains
/// a type field for which addressing mode is used by a MicroUri. The `AddressType` type implements this definition.
#[derive(Debug, Copy, Clone, PartialEq)]
Expand Down
10 changes: 10 additions & 0 deletions src/uri/uentity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@

pub use crate::up_core_api::uri::UEntity;
use crate::uri::UUriError;
use std::hash::{Hash, Hasher};

const UENTITY_ID_LENGTH: usize = 16;
const UENTITY_ID_VALID_BITMASK: u32 = 0xffff << UENTITY_ID_LENGTH;
const UENTITY_MAJOR_VERSION_LENGTH: usize = 8;
const UENTITY_MAJOR_VERSION_VALID_BITMASK: u32 = 0xffffff << UENTITY_MAJOR_VERSION_LENGTH;

impl Hash for UEntity {
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state);
self.version_major.hash(state);
}
}

impl Eq for UEntity {}

impl UEntity {
pub fn has_id(&self) -> bool {
self.id.is_some()
Expand Down
9 changes: 9 additions & 0 deletions src/uri/uresource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@

pub use crate::up_core_api::uri::UResource;
use crate::uri::UUriError;
use std::hash::{Hash, Hasher};

const URESOURCE_ID_LENGTH: usize = 16;
const URESOURCE_ID_VALID_BITMASK: u32 = 0xffff << URESOURCE_ID_LENGTH;

impl Hash for UResource {
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}

impl Eq for UResource {}

impl UResource {
pub fn has_id(&self) -> bool {
self.id.is_some()
Expand Down
Loading