uqa_execution/catalog/sequence/
decode.rs1use super::{
10 sequence_cache_size_default, sequence_state_called_default, SequenceDataType, SequenceState,
11};
12
13impl<'de> serde::Deserialize<'de> for SequenceState {
14 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
15 where
16 D: serde::Deserializer<'de>,
17 {
18 #[derive(serde::Deserialize)]
19 struct Representation {
20 start: i64,
21 increment: i64,
22 current: i64,
23 #[serde(default = "sequence_state_called_default")]
24 called: bool,
25 #[serde(default)]
26 log_count: i64,
27 #[serde(default)]
28 data_type: SequenceDataType,
29 #[serde(default)]
30 min_value: Option<i64>,
31 #[serde(default)]
32 max_value: Option<i64>,
33 #[serde(default)]
34 cycle: bool,
35 #[serde(default = "sequence_cache_size_default")]
36 cache_size: i64,
37 #[serde(default)]
38 definition_generation: [u8; 16],
39 #[serde(default)]
40 owner: Option<super::SequenceOwner>,
41 }
42
43 let representation = Representation::deserialize(deserializer)?;
44 let (type_min, type_max) = representation.data_type.bounds();
45 Ok(Self {
46 start: representation.start,
47 increment: representation.increment,
48 current: representation.current,
49 called: representation.called,
50 log_count: representation.log_count,
51 data_type: representation.data_type,
52 min_value: representation
53 .min_value
54 .unwrap_or(if representation.increment > 0 {
55 1
56 } else {
57 type_min
58 }),
59 max_value: representation
60 .max_value
61 .unwrap_or(if representation.increment > 0 {
62 type_max
63 } else {
64 -1
65 }),
66 cycle: representation.cycle,
67 cache_size: representation.cache_size,
68 definition_generation: representation.definition_generation,
69 owner: representation.owner,
70 })
71 }
72}