1use super::*;
2
3#[inline(always)]
5pub fn sto_subfield(sto: &[u8], field_id: FieldId) -> Result<&[u8]> {
6 let res = unsafe { _c::sto_subfield(sto.as_ptr() as u32, sto.len() as u32, field_id as _) };
7
8 let location = match res {
9 res if res >= 0 => res,
10 res => return Err(Error::from_code(res as _)),
11 };
12
13 Ok(&sto[range_from_location(location)])
14}
15
16#[inline(always)]
18pub fn sto_subarray(sto: &[u8], array_id: u32) -> Result<&[u8]> {
19 let res = unsafe { _c::sto_subarray(sto.as_ptr() as u32, sto.len() as u32, array_id) };
20
21 let location = match res {
22 res if res >= 0 => res,
23 res => return Err(Error::from_code(res as _)),
24 };
25
26 Ok(&sto[range_from_location(location)])
27}
28
29#[inline(always)]
31pub fn sto_emplace(
32 sto_out: &mut [u8],
33 sto_src: &[u8],
34 field: &[u8],
35 field_id: FieldId,
36) -> Result<u64> {
37 let res = unsafe {
38 _c::sto_emplace(
39 sto_out.as_mut_ptr() as u32,
40 sto_out.len() as u32,
41 sto_src.as_ptr() as u32,
42 sto_src.len() as u32,
43 field.as_ptr() as u32,
44 field.len() as u32,
45 field_id as _,
46 )
47 };
48
49 result_u64(res)
50}
51
52#[inline(always)]
54pub fn sto_erase(sto_out: &mut [u8], sto_src: &[u8], field_id: FieldId) -> Result<u64> {
55 let res = unsafe {
56 _c::sto_erase(
57 sto_out.as_mut_ptr() as u32,
58 sto_out.len() as u32,
59 sto_src.as_ptr() as u32,
60 sto_src.len() as u32,
61 field_id as _,
62 )
63 };
64
65 result_u64(res)
66}
67
68#[inline(always)]
70pub fn sto_validate(sto: &[u8]) -> bool {
71 let res = buf_read(sto, _c::sto_validate);
72
73 match res {
74 Ok(0) => false,
75 Ok(1) => true,
76 _ => false,
77 }
78}