nativeview_hybrid_spec/model/
batch_model.rs1use crate::model::direct_model::{DirectErrKind, DirectReturnSpec};
6use crate::schema::{HybridFileSpec, HybridMethodSpec, HybridModuleSpec, HybridType};
7
8#[derive(Debug, Clone)]
10pub struct DirectBatchMethodSpec<'a> {
11 pub method: &'a HybridMethodSpec,
12 pub opcode: u16,
14 pub ret: DirectReturnSpec,
15 pub ok_ty: &'a HybridType,
16 pub has_reply: bool,
17}
18
19#[derive(Debug, Clone)]
21pub struct DirectBatchSpec<'a> {
22 pub module: &'a HybridModuleSpec,
23 pub methods: Vec<DirectBatchMethodSpec<'a>>,
24 pub has_replies: bool,
26 pub err_kind: DirectErrKind,
29}
30
31impl<'a> DirectBatchSpec<'a> {
32 pub fn from_module(m: &'a HybridModuleSpec, spec: &HybridFileSpec) -> Option<Self> {
34 let mut methods = Vec::new();
35 let mut has_replies = false;
36 let mut err_kind: Option<DirectErrKind> = None;
37
38 for (idx, method) in m.methods.iter().enumerate() {
39 if !method.batchable {
40 continue;
41 }
42 let ret = DirectReturnSpec::classify(method, spec);
43 let ok_ty = ret.ok_hybrid_type(method);
44 let has_reply = !matches!(ok_ty, HybridType::Void);
45 has_replies |= has_reply;
46 if err_kind.is_none() && ret.err != DirectErrKind::None {
47 err_kind = Some(ret.err.clone());
48 }
49 methods.push(DirectBatchMethodSpec {
50 method,
51 opcode: (idx + 1) as u16,
52 ret,
53 ok_ty,
54 has_reply,
55 });
56 }
57 if methods.is_empty() {
58 return None;
59 }
60 Some(Self {
61 module: m,
62 methods,
63 has_replies,
64 err_kind: err_kind.unwrap_or(DirectErrKind::ModStatus),
65 })
66 }
67
68 #[inline]
70 pub fn uses_err_sink(&self) -> bool {
71 self.err_kind == DirectErrKind::String
72 }
73
74 #[inline]
76 pub fn any_borrowed_param(&self) -> bool {
77 self.methods.iter().any(|bm| {
78 bm.method
79 .params
80 .iter()
81 .any(|p| matches!(p.ty, HybridType::String | HybridType::Bytes))
82 })
83 }
84}