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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use crate::{containers::ByteSlice, macros::wrap};
use servicepoint::{
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Packet,
};
use std::ptr::NonNull;
wrap! {
DisplayBitVec {
derives: crate::containers::derive_container;
functions:
/// Creates a new [DisplayBitVec] instance.
///
/// # Arguments
///
/// - `size`: size in bits.
///
/// returns: [DisplayBitVec] with all bits set to false.
///
/// # Panics
///
/// - when `size` is not divisible by 8.
fn new(size: val usize) -> move NonNull<DisplayBitVec> {
DisplayBitVec::repeat(false, size)
};
/// Interpret the data as a series of bits and load then into a new [DisplayBitVec] instance.
///
/// returns: [DisplayBitVec] instance containing data.
fn load(data: slice ByteSlice) -> move NonNull<DisplayBitVec> {
DisplayBitVec::from_slice(data)
};
methods:
/// Creates a [BitVecCommand] and immediately turns that into a [Packet].
///
/// The provided [DisplayBitVec] gets consumed.
///
/// Returns NULL in case of an error.
fn try_into_packet(
move bitvec,
offset: val usize,
operation: val BinaryOperation,
compression: val CompressionCode
) -> move_ok *mut Packet {
Packet::try_from(BitVecCommand {
bitvec,
offset,
operation,
compression,
})
};
/// Gets the value of a bit.
///
/// # Arguments
///
/// - `bit_vec`: instance to read from
/// - `index`: the bit index to read
///
/// returns: value of the bit
///
/// # Panics
///
/// - when accessing `index` out of bounds
fn get(ref instance, index: val usize) -> val bool {
instance.get(index).map(|x| *x).unwrap_or(false)
};
/// Sets the value of a bit.
///
/// # Arguments
///
/// - `index`: the bit index to edit
/// - `value`: the value to set the bit to
///
/// # Panics
///
/// - when accessing `index` out of bounds
fn set(mut instance, index: val usize, value: val bool);
/// Sets the value of all bits.
///
/// # Arguments
///
/// - `value`: the value to set all bits to
fn fill(mut instance, value: val bool);
/// Gets the length in bits.
fn len(ref instance) -> val usize;
/// Returns true if length is 0.
fn is_empty(ref instance) -> val bool;
/// Gets an unsafe reference to the data of the [DisplayBitVec] instance.
///
/// The returned memory is valid for the lifetime of the bitvec.
fn as_raw_mut_slice(mut instance) -> slice ByteSlice;
}
}