Skip to main content

capnp/
raw.rs

1// Copyright (c) 2018 the capnproto-rust contributors
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21//! Functions providing low level access to encoded data.
22
23use crate::traits::{IntoInternalListReader, IntoInternalStructReader};
24
25/// Gets a slice view of the data section of a struct.
26pub fn get_struct_data_section<'a, T>(value: T) -> &'a [u8]
27where
28    T: IntoInternalStructReader<'a>,
29{
30    value
31        .into_internal_struct_reader()
32        .get_data_section_as_blob()
33}
34
35/// Gets the pointer section as a list.
36pub fn get_struct_pointer_section<'a, T>(value: T) -> crate::any_pointer_list::Reader<'a>
37where
38    T: IntoInternalStructReader<'a>,
39{
40    crate::any_pointer_list::Reader::new(
41        value
42            .into_internal_struct_reader()
43            .get_pointer_section_as_list(),
44    )
45}
46
47/// Gets the size of the elements in a list.
48pub fn get_list_element_size<'a, T>(value: T) -> crate::private::layout::ElementSize
49where
50    T: IntoInternalListReader<'a>,
51{
52    value.into_internal_list_reader().get_element_size()
53}
54
55/// Gets the number of bits between successive elements in a list.
56pub fn get_list_step_size_in_bits<'a, T>(value: T) -> u32
57where
58    T: IntoInternalListReader<'a>,
59{
60    value.into_internal_list_reader().get_step_size_in_bits()
61}
62
63/// Gets a slice view of a list, excluding any tag word.
64pub fn get_list_bytes<'a, T>(value: T) -> &'a [u8]
65where
66    T: IntoInternalListReader<'a>,
67{
68    value.into_internal_list_reader().into_raw_bytes()
69}