Skip to main content

MemoryGatewayTransport

Struct MemoryGatewayTransport 

Source
pub struct MemoryGatewayTransport { /* private fields */ }
Expand description

内存 Gateway 传输实现 — 用于测试和开发环境

不进行实际网络通信,所有状态保存在内存中,供测试断言使用。

§数据结构

  • client_messages: client_id → messages 队列(键存在即表示 client 在线)
  • client_groups: client_id → groups 映射
  • group_clients: group → client_ids 映射

§线程安全

通过 Arc<Mutex<GatewayState>> 保护,支持并发访问。所有操作在单个锁内完成, 保证多字段状态的一致性。

§用法

use sz_rust_auth_facade::gateway::{MemoryGatewayTransport, GatewayTransport};

let transport = MemoryGatewayTransport::new();
transport.register_client("7f00000108fc00000001");
transport.send_to_client("7f00000108fc00000001", "hello").unwrap();
assert_eq!(transport.client_messages("7f00000108fc00000001"), vec!["hello".to_string()]);

Implementations§

Source§

impl MemoryGatewayTransport

Source

pub fn new() -> MemoryGatewayTransport

创建新的内存传输

Source

pub fn register_client(&self, client_id: &str)

注册客户端(标记为在线)

非 trait 方法,供测试/开发注册在线客户端。对齐 PHP GatewayWorker 中客户端连接 建立后自动上线的行为。重复注册为幂等操作。

§参数
  • client_id: 客户端 ID
Source

pub fn client_messages(&self, client_id: &str) -> Vec<String>

获取客户端收到的所有消息(快照)

非 trait 方法,供测试断言。客户端不在线时返回空 Vec。

§参数
  • client_id: 客户端 ID

Trait Implementations§

Source§

impl Debug for MemoryGatewayTransport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for MemoryGatewayTransport

Source§

fn default() -> MemoryGatewayTransport

Returns the “default value” for a type. Read more
Source§

impl GatewayTransport for MemoryGatewayTransport

Source§

fn send_to_client( &self, client_id: &str, message: &str, ) -> Result<(), GatewayError>

向指定 client_id 发送消息 Read more
Source§

fn send_to_clients( &self, client_ids: &[String], message: &str, ) -> Result<(), GatewayError>

向多个 client_id 发送消息 Read more
Source§

fn send_to_all(&self, message: &str) -> Result<(), GatewayError>

向所有在线 client_id 发送广播 Read more
Source§

fn send_to_group(&self, group: &str, message: &str) -> Result<(), GatewayError>

向指定群组发送消息 Read more
Source§

fn get_all_client_ids(&self) -> Result<Vec<String>, GatewayError>

获取所有在线 client_id
Source§

fn get_client_id_list_by_group( &self, group: &str, ) -> Result<Vec<String>, GatewayError>

获取指定群组中的 client_id Read more
Source§

fn get_groups_by_client_id( &self, client_id: &str, ) -> Result<Vec<String>, GatewayError>

获取 client_id 所在的群组 Read more
Source§

fn join_group(&self, client_id: &str, group: &str) -> Result<(), GatewayError>

将 client_id 加入群组 Read more
Source§

fn leave_group(&self, client_id: &str, group: &str) -> Result<(), GatewayError>

将 client_id 离开群组 Read more
Source§

fn ungroup(&self, group: &str) -> Result<(), GatewayError>

解散指定群组(对齐 PHP Gateway::ungroup()Read more
Source§

fn is_online(&self, client_id: &str) -> Result<bool, GatewayError>

判断 client_id 是否在线
Source§

fn get_client_count(&self) -> Result<usize, GatewayError>

获取在线 client_id 数量
Source§

fn get_client_count_by_group(&self, group: &str) -> Result<usize, GatewayError>

获取指定群组的在线 client_id 数量 Read more
Source§

fn close_client(&self, client_id: &str) -> Result<(), GatewayError>

关闭指定 client_id 的连接 Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more