Struct ic_websocket_cdk::types::OnMessageCallbackArgs
source · pub struct OnMessageCallbackArgs {
pub client_principal: ClientPrincipal,
pub message: Vec<u8>,
}
Expand description
Arguments passed to the on_message
handler.
The message
argument is the message received from the client, serialized in Candid.
To deserialize the message, use candid::decode_one.
§Example
This example is the deserialize equivalent of the send’s example serialize one.
use candid::{decode_one, CandidType};
use ic_websocket_cdk::OnMessageCallbackArgs;
use serde::Deserialize;
#[derive(CandidType, Deserialize)]
struct MyMessage {
some_field: String,
}
fn on_message(args: OnMessageCallbackArgs) {
let received_message: MyMessage = decode_one(&args.message).unwrap();
println!("Received message: some_field: {:?}", received_message.some_field);
}
Fields§
§client_principal: ClientPrincipal
The principal of the client sending the message to the canister.
message: Vec<u8>
The message received from the client, serialized in Candid. See OnMessageCallbackArgs for an example on how to deserialize the message.
Auto Trait Implementations§
impl RefUnwindSafe for OnMessageCallbackArgs
impl Send for OnMessageCallbackArgs
impl Sync for OnMessageCallbackArgs
impl Unpin for OnMessageCallbackArgs
impl UnwindSafe for OnMessageCallbackArgs
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more