Skip to main content

decode_add_message

Function decode_add_message 

Source
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 (line 15)
4fn main() -> anyhow::Result<()> {
5    if std::env::args().skip(1).any(|arg| arg == "--help") {
6        println!("sync_once: approve a test-account QR login and summarize one initial sync page.");
7        return Ok(());
8    }
9    let (client, mut state) = support::login()?;
10    let batch = client.sync(&mut state, &[])?;
11    let mut messages = 0;
12    for command in &batch.commands {
13        if command.id == 5 {
14            let _message =
15                wechat_protocol::wire::decode_add_message(&command.payload, &state.own_username)?;
16            messages += 1;
17        }
18    }
19    println!(
20        "commands={} add_messages={} other_commands={} continuation={}",
21        batch.commands.len(),
22        messages,
23        batch.commands.len() - messages,
24        batch.continuation
25    );
26    // This is a preview, not a sync consumer: all raw commands remain in `batch`,
27    // and we never save its returned cursor. A persistent client must retain and
28    // handle every required command before committing that cursor.
29    println!("Preview only. No history or sync cursor was saved.");
30    Ok(())
31}