mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
add schemars_1 feature
This commit is contained in:
parent
b71925baad
commit
25a28172ad
5 changed files with 74 additions and 8 deletions
|
|
@ -882,3 +882,22 @@ impl<'a, E: Endianness> schemars::JsonSchema for BitReadStream<'a, E> {
|
|||
StreamSchema::json_schema(gen)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "schemars_1")]
|
||||
impl<'a, E: Endianness> schemars_1::JsonSchema for BitReadStream<'a, E> {
|
||||
fn schema_name() -> std::borrow::Cow<'static, str> {
|
||||
"BitReadStream".into()
|
||||
}
|
||||
|
||||
fn json_schema(gen: &mut schemars_1::SchemaGenerator) -> schemars_1::Schema {
|
||||
use schemars_1 as schemars;
|
||||
|
||||
#[derive(schemars_1::JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
struct StreamSchema {
|
||||
data: Vec<u8>,
|
||||
bit_length: usize,
|
||||
}
|
||||
StreamSchema::json_schema(gen)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ impl<'a, E: Endianness> WriteBuffer<'a, E> {
|
|||
} else {
|
||||
0
|
||||
};
|
||||
let merged_byte_count = (count + bit_offset + 7) / 8;
|
||||
let merged_byte_count = (count + bit_offset).div_ceil(8);
|
||||
|
||||
if E::is_le() {
|
||||
let merged = last_written_byte as usize | (bits << bit_offset);
|
||||
|
|
@ -174,7 +174,7 @@ impl<'a, E: Endianness> WriteBuffer<'a, E> {
|
|||
|
||||
let bit_offset = pos & 7;
|
||||
let byte_pos = pos / 8;
|
||||
let byte_count = (count + bit_offset + 7) / 8;
|
||||
let byte_count = (count + bit_offset).div_ceil(8);
|
||||
|
||||
let mut old = [0; 8];
|
||||
old[0..byte_count].copy_from_slice(&self.bytes[byte_pos..byte_pos + byte_count]);
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ where
|
|||
|
||||
/// The number of written bytes in the buffer
|
||||
pub fn byte_len(&self) -> usize {
|
||||
(self.buffer.bit_len() + 7) / 8
|
||||
self.buffer.bit_len().div_ceil(8)
|
||||
}
|
||||
|
||||
fn push_non_fit_bits<I>(&mut self, bits: I, count: usize)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue