1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright (c) 2020-2024 COMBINE-lab.
*
* This file is part of libradicl
* (see https://www.github.com/COMBINE-lab/libradicl).
*
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause
*/
//! This module contains some utility constants and functions that are
//! helpful in processing RAD information.
use Pread;
pub const MASK_TOP_BIT_U32: u32 = 0x7FFFFFFF;
pub const MASK_LOWER_31_U32: u32 = 0x80000000;
pub const SPLICE_MASK_U32: u32 = 0xFFFFFFFE;
/// Check if more can be read from the underlying file buffer (e.g. to check if another chunk may exist).
/// **NOTE**: This doesn't guarantee that an entire properly formed semantic object exists in the file
/// starting at the current point, but just that it may. In the future, we should consider adding
/// `try_from_bytes` to the relevant structures to complement the `from_bytes` in the case that reading the next
/// object may fail.
/// **NOTE**: This is taken from [Rust's std
/// library](https://doc.rust-lang.org/src/std/io/mod.rs.html#2279-2281).
/// **TODO**: Replace this with Rust's own `has_data_left` once that is stabilized.
/// Reads the header of a chunk, returning the number of bytes and number of records.
/// Returns [Ok(u32, u32)] on success and an [std::io::Error] if there was a problem
/// reading the header.
///
/// In the returned tuple, the first [u32] is the number of bytes in the chunk and the
/// second [u32] is the number of records in the chunk.
///
/// This function lives in util and outside of the [Chunk] trait because it is agnostic
/// to the type of the chunk (i.e. the record type).