fastlib/base/message.rs
1use crate::{Result, ValueType};
2use crate::Value;
3
4/// Defines the interface for message factories.
5///
6/// The callback functions are called when the specific event occurs during message processing.
7///
8pub trait MessageFactory {
9 /// Called when a \<template> processing is started.
10 /// * `id` is the template id;
11 /// * `name` is the template name.
12 fn start_template(&mut self, id: u32, name: &str);
13
14 /// Called when a \<template> processing is finished.
15 fn stop_template(&mut self);
16
17 /// Called when a field element is processed.
18 /// * `id` is the field instruction id;
19 /// * `name` is the field name;
20 /// * `value` is the field value which is optional.
21 fn set_value(&mut self, id: u32, name: &str, value: Option<Value>);
22
23 /// Called when a \<sequence> element processing is started.
24 /// * `id` is the sequence instruction id; can be `0` if id is not specified;
25 /// * `name` is the sequence name;
26 /// * `length` is the sequence length.
27 fn start_sequence(&mut self, id: u32, name: &str, length: u32);
28
29 /// Called when a sequence item processing is started.
30 /// * `index` is the sequence item index.
31 fn start_sequence_item(&mut self, index: u32);
32
33 /// Called when a sequence item processing is finished.
34 fn stop_sequence_item(&mut self);
35
36 /// Called when a \<sequence> processing is finished.
37 fn stop_sequence(&mut self);
38
39 /// Called when a \<group> element processing is started.
40 /// * `name` is the group name.
41 fn start_group(&mut self, name: &str);
42
43 /// Called when a \<group> element processing is finished.
44 fn stop_group(&mut self);
45
46 /// Called when a template reference (\<templateRef>) processing is started.
47 /// * `name` is the template name;
48 /// * `dynamic` is `true` if the template reference is dynamic.
49 fn start_template_ref(&mut self, name: &str, dynamic: bool);
50
51 /// Called when a template reference (\<templateRef>) processing is finished.
52 fn stop_template_ref(&mut self);
53}
54
55/// Defines the interface for message visitors.
56///
57/// The callback functions are called when the specific information required during message processing.
58///
59pub trait MessageVisitor {
60 fn get_template_name(&mut self) -> Result<String>;
61
62 fn get_value(&mut self, name: &str, type_: &ValueType) -> Result<Option<Value>>;
63
64 fn select_group(&mut self, name: &str) -> Result<bool>;
65
66 fn release_group(&mut self) -> Result<()>;
67
68 fn select_sequence(&mut self, name: &str) -> Result<Option<usize>>;
69
70 fn select_sequence_item(&mut self, index: usize) -> Result<()>;
71
72 fn release_sequence_item(&mut self) -> Result<()>;
73
74 fn release_sequence(&mut self) -> Result<()>;
75
76 fn select_template_ref(&mut self, name: &str, dynamic: bool) -> Result<Option<String>>;
77
78 fn release_template_ref(&mut self) -> Result<()>;
79}