1use crate::{
2 helpers::{read_as, GribInt},
3 DecodeError,
4};
5
6pub(crate) struct Section5Param {
7 pub(crate) num_points_encoded: u32,
8 pub(crate) template_num: u16,
9}
10
11impl Section5Param {
12 pub(crate) fn from_buf(buf: &[u8]) -> Self {
13 let num_points_encoded = read_as!(u32, buf, 0);
14 let template_num = read_as!(u16, buf, 4);
15 Self {
16 num_points_encoded,
17 template_num,
18 }
19 }
20}
21
22pub(crate) struct SimplePackingParam {
23 pub(crate) ref_val: f32,
24 pub(crate) exp: i16,
25 pub(crate) dig: i16,
26 pub(crate) nbit: u8,
27}
28
29impl SimplePackingParam {
30 pub(crate) fn from_buf(buf: &[u8]) -> Result<Self, DecodeError> {
31 let ref_val = read_as!(f32, buf, 0);
32 let exp = read_as!(u16, buf, 4).as_grib_int();
33 let dig = read_as!(u16, buf, 6).as_grib_int();
34 let nbit = read_as!(u8, buf, 8);
35 let original_field_type_value = read_as!(u8, buf, 9);
36
37 if original_field_type_value != 0 {
38 return Err(crate::DecodeError::NotSupported(
39 "GRIB2 code table 5.1 (type of original field values)",
40 original_field_type_value.into(),
41 ));
42 }
43
44 Ok(Self {
45 ref_val,
46 exp,
47 dig,
48 nbit,
49 })
50 }
51
52 pub(crate) fn zero_bit_reference_value(&self) -> f32 {
53 self.ref_val * 10_f32.powi(-i32::from(self.dig))
54 }
55}
56
57pub(crate) struct ComplexPackingParam {
58 pub(crate) group_splitting_method_used: u8,
59 pub(crate) missing_value_management_used: u8,
60 pub(crate) ngroup: u32,
61 pub(crate) group_width_ref: u8,
62 pub(crate) group_width_nbit: u8,
63 pub(crate) group_len_ref: u32,
64 pub(crate) group_len_inc: u8,
65 pub(crate) group_len_last: u32,
66 pub(crate) group_len_nbit: u8,
67}
68
69impl ComplexPackingParam {
70 pub(crate) fn from_buf(buf: &[u8]) -> Self {
71 let group_splitting_method_used = read_as!(u8, buf, 0);
72 let missing_value_management_used = read_as!(u8, buf, 1);
73 let ngroup = read_as!(u32, buf, 10);
74 let group_width_ref = read_as!(u8, buf, 14);
75 let group_width_nbit = read_as!(u8, buf, 15);
76 let group_len_ref = read_as!(u32, buf, 16);
77 let group_len_inc = read_as!(u8, buf, 20);
78 let group_len_last = read_as!(u32, buf, 21);
79 let group_len_nbit = read_as!(u8, buf, 25);
80 Self {
81 group_splitting_method_used,
82 missing_value_management_used,
83 ngroup,
84 group_width_ref,
85 group_width_nbit,
86 group_len_ref,
87 group_len_inc,
88 group_len_last,
89 group_len_nbit,
90 }
91 }
92}
93
94pub(crate) struct SpatialDifferencingParam {
95 pub(crate) order: u8,
96 pub(crate) extra_desc_num_octets: u8,
97}
98
99impl SpatialDifferencingParam {
100 pub(crate) fn from_buf(buf: &[u8]) -> Self {
101 let order = read_as!(u8, buf, 0);
102 let extra_desc_num_octets = read_as!(u8, buf, 1);
103 Self {
104 order,
105 extra_desc_num_octets,
106 }
107 }
108}
109
110#[cfg(feature = "ccsds-unpack-with-libaec")]
111pub(crate) struct CcsdsCompressionParam {
112 pub(crate) mask: u8,
113 pub(crate) block_size: u8,
114 pub(crate) reference_sample_interval: u16,
115}
116
117#[cfg(feature = "ccsds-unpack-with-libaec")]
118impl CcsdsCompressionParam {
119 pub(crate) fn from_buf(buf: &[u8]) -> Self {
120 let mask = read_as!(u8, buf, 0);
121 let block_size = read_as!(u8, buf, 1);
122 let reference_sample_interval = read_as!(u16, buf, 2);
123 Self {
124 mask,
125 block_size,
126 reference_sample_interval,
127 }
128 }
129}
130
131pub(crate) struct RunLengthPackingParam {
132 pub(crate) nbit: u8,
133 pub(crate) maxv: u16,
134 pub(crate) max_level: u16,
135 pub(crate) num_digits: u8,
136}
137
138impl RunLengthPackingParam {
139 pub(crate) fn from_buf(buf: &[u8]) -> Self {
140 let nbit = read_as!(u8, buf, 0);
141 let maxv = read_as!(u16, buf, 1);
142 let max_level = read_as!(u16, buf, 3);
143 let num_digits = read_as!(u8, buf, 5);
144 Self {
145 nbit,
146 maxv,
147 max_level,
148 num_digits,
149 }
150 }
151}