malbox_plugin_sdk/context/message.rs
1//! Internal result message types for the plugin-runtime channel.
2//!
3//! These decouple the shared Context/ResultSink API from the gRPC transport
4//! types (proto::TaskResult, tonic::Status), allowing host plugins to avoid
5//! pulling in tonic/prost.
6
7/// Wire format hint attached to result data so the receiver knows how to
8/// interpret the bytes.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum ResultFormat {
11 /// The data is valid JSON (UTF-8 encoded).
12 Json,
13 /// The data is arbitrary binary.
14 Bytes,
15 /// Format is unknown or not applicable (e.g. for ref messages).
16 Unspecified,
17}
18
19/// What a [`TaskResultMessage`] represents.
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub enum ResultKind {
22 /// A normal inline result.
23 Result,
24 /// A reference to a stashed large result (handle in `stash_handle`).
25 ResultRef,
26 /// A progress update (not a final result).
27 Progress,
28}
29
30/// Transport-agnostic result message sent from [`ResultSink`](super::ResultSink)
31/// to the runtime, which converts it to the appropriate wire format
32/// (e.g. `proto::TaskResult` for gRPC, postcard for IPC).
33#[derive(Debug, Clone)]
34pub struct TaskResultMessage {
35 /// ID of the task this result belongs to.
36 pub task_id: i32,
37 /// Logical name identifying this result (e.g. `"yara_matches"`).
38 pub result_name: String,
39 /// Payload bytes (inline result data, or empty for ref messages).
40 pub data: Vec<u8>,
41 /// How to interpret `data`.
42 pub format: ResultFormat,
43 /// Whether this is the final message for the task.
44 pub is_final: bool,
45 /// What kind of message this is (inline result, stash ref, or progress).
46 pub kind: ResultKind,
47 /// For ResultRef: the stash handle. Empty for inline results.
48 pub stash_handle: String,
49 /// For ResultRef: format of the original stashed data.
50 pub stash_format: ResultFormat,
51 /// For ResultRef: byte size of the stashed data.
52 pub stash_size: u64,
53}