mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
partially passing encoder
This commit is contained in:
@@ -20,37 +20,37 @@ use crate::common::BitArray;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub struct BinaryShiftToken {
|
||||
binaryShiftStart: u32,
|
||||
binaryShiftByteCount: u32,
|
||||
binary_shift_start: u32,
|
||||
binary_shift_byte_count: u32,
|
||||
}
|
||||
|
||||
impl BinaryShiftToken {
|
||||
pub fn new(binaryShiftStart: u32, binaryShiftByteCount: u32) -> Self {
|
||||
pub fn new(binary_shift_start: u32, binary_shift_byte_count: u32) -> Self {
|
||||
Self {
|
||||
binaryShiftStart,
|
||||
binaryShiftByteCount,
|
||||
binary_shift_start,
|
||||
binary_shift_byte_count,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn appendTo(&self, bitArray: &mut BitArray, text: &[u8]) {
|
||||
let bsbc = self.binaryShiftByteCount as usize;
|
||||
pub fn appendTo(&self, bit_array: &mut BitArray, text: &[u8]) {
|
||||
let bsbc = self.binary_shift_byte_count as usize;
|
||||
for i in 0..bsbc {
|
||||
// for (int i = 0; i < bsbc; i++) {
|
||||
if (i == 0 || (i == 31 && bsbc <= 62)) {
|
||||
if i == 0 || (i == 31 && bsbc <= 62) {
|
||||
// We need a header before the first character, and before
|
||||
// character 31 when the total byte code is <= 62
|
||||
bitArray.appendBits(31, 5); // BINARY_SHIFT
|
||||
if (bsbc > 62) {
|
||||
bitArray.appendBits(bsbc as u32 - 31, 16);
|
||||
} else if (i == 0) {
|
||||
bit_array.appendBits(31, 5).unwrap(); // BINARY_SHIFT
|
||||
if bsbc > 62 {
|
||||
bit_array.appendBits(bsbc as u32 - 31, 16).unwrap();
|
||||
} else if i == 0 {
|
||||
// 1 <= binaryShiftByteCode <= 62
|
||||
bitArray.appendBits(bsbc.min(31) as u32, 5);
|
||||
bit_array.appendBits(bsbc.min(31) as u32, 5).unwrap();
|
||||
} else {
|
||||
// 32 <= binaryShiftCount <= 62 and i == 31
|
||||
bitArray.appendBits(bsbc as u32 - 31, 5);
|
||||
bit_array.appendBits(bsbc as u32 - 31, 5).unwrap();
|
||||
}
|
||||
}
|
||||
bitArray.appendBits(text[self.binaryShiftStart as usize + i].into(), 8);
|
||||
bit_array.appendBits(text[self.binary_shift_start as usize + i].into(), 8).expect("should never fail to append");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ impl fmt::Display for BinaryShiftToken {
|
||||
write!(
|
||||
f,
|
||||
"<{}::{}>",
|
||||
self.binaryShiftStart,
|
||||
(self.binaryShiftStart + self.binaryShiftByteCount - 1)
|
||||
self.binary_shift_start,
|
||||
(self.binary_shift_start + self.binary_shift_byte_count - 1)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user