pub fn decode_add_message(
input: &[u8],
own_username: &str,
) -> Result<AddMessage>Expand description
Decode AddMsg command 5. Fields 6/7 remain numbered. Present field 13 has a bounded official server_seq correlation; this does not enable every message class for official writes. A room’s actual sender requires separate, validated group-envelope/member resolution and is deliberately unresolved here.
Examples found in repository?
examples/sync_once.rs (lines 16-19)
5async fn main() -> anyhow::Result<()> {
6 if std::env::args().skip(1).any(|arg| arg == "--help") {
7 println!("sync_once: approve a test-account QR login and summarize one initial sync page.");
8 return Ok(());
9 }
10 let client = tokio::task::spawn_blocking(support::login).await??;
11 let identity = client.account_identity()?;
12 let batch = client.sync(&[]).await?;
13 let mut messages = 0;
14 for command in &batch.commands {
15 if command.id == 5 {
16 let _message = wechat_protocol::wire::decode_add_message(
17 &command.payload,
18 &identity.own_username,
19 )?;
20 messages += 1;
21 }
22 }
23 println!(
24 "commands={} add_messages={} other_commands={} continuation={}",
25 batch.commands.len(),
26 messages,
27 batch.commands.len() - messages,
28 batch.continuation
29 );
30 // This is a preview, not a sync consumer: all raw commands remain in `batch`,
31 // and we never save its returned cursor. A persistent client must retain and
32 // handle every required command before committing that cursor.
33 println!("Preview only. No history or sync cursor was saved.");
34 client.shutdown().await?;
35 Ok(())
36}