[−][src]Struct qr_code::bits::Bits
The Bits
structure stores the encoded data for a QR code.
Implementations
impl Bits
[src]
pub fn new(version: Version) -> Self
[src]
Constructs a new, empty bits structure.
pub fn push_number_checked(&mut self, n: usize, number: usize) -> QrResult<()>
[src]
Pushes an N-bit big-endian integer to the end of the bits, and check that the number does not overflow the bits.
Returns Err(QrError::DataTooLong)
on overflow.
pub fn into_bytes(self) -> Vec<u8>
[src]
Convert the bits into a bytes vector.
pub fn len(&self) -> usize
[src]
Total number of bits currently pushed.
pub fn is_empty(&self) -> bool
[src]
Whether there are any bits pushed.
pub fn max_len(&self, ec_level: EcLevel) -> QrResult<usize>
[src]
The maximum number of bits allowed by the provided QR code version and error correction level.
Errors
Returns Err(QrError::InvalidVersion)
if it is not valid to use the
ec_level
for the given version (e.g. Version::Micro(1)
with
EcLevel::H
).
pub fn version(&self) -> Version
[src]
Version of the QR code.
impl Bits
[src]
pub fn push_mode_indicator(&mut self, mode: ExtendedMode) -> QrResult<()>
[src]
Push the mode indicator to the end of the bits.
Errors
If the mode is not supported in the provided version, this method
returns Err(QrError::UnsupportedCharacterSet)
.
impl Bits
[src]
pub fn push_eci_designator(&mut self, eci_designator: u32) -> QrResult<()>
[src]
Push an ECI (Extended Channel Interpretation) designator to the bits.
An ECI designator is a 6-digit number to specify the character set of
the following binary data. After calling this method, one could call
.push_byte_data()
or similar methods to insert the actual data, e.g.
#![allow(unused_must_use)] use qr_code::bits::Bits; use qr_code::types::Version; let mut bits = Bits::new(Version::Normal(1)); bits.push_eci_designator(9); // 9 = ISO-8859-7 (Greek). bits.push_byte_data(b"\xa1\xa2\xa3\xa4\xa5"); // ΑΒΓΔΕ
The full list of ECI designator values can be found from http://strokescribe.com/en/ECI.html. Some example values are:
ECI # | Character set |
---|---|
3 | ISO-8859-1 (Western European) |
20 | Shift JIS (Japanese) |
23 | Windows 1252 (Latin 1) (Western European) |
25 | UTF-16 Big Endian |
26 | UTF-8 |
28 | Big 5 (Traditional Chinese) |
29 | GB-18030 (Simplified Chinese) |
30 | EUC-KR (Korean) |
Errors
If the QR code version does not support ECI, this method will return
Err(QrError::UnsupportedCharacterSet)
.
If the designator is outside of the expected range, this method will
return Err(QrError::InvalidECIDesignator)
.
impl Bits
[src]
pub fn push_numeric_data(&mut self, data: &[u8]) -> QrResult<()>
[src]
Encodes a numeric string to the bits.
The data should only contain the characters 0 to 9.
Errors
Returns Err(QrError::DataTooLong)
on overflow.
impl Bits
[src]
pub fn push_alphanumeric_data(&mut self, data: &[u8]) -> QrResult<()>
[src]
Encodes an alphanumeric string to the bits.
The data should only contain the charaters A to Z (excluding lowercase),
0 to 9, space, $
, %
, *
, +
, -
, .
, /
or :
.
Errors
Returns Err(QrError::DataTooLong)
on overflow.
impl Bits
[src]
impl Bits
[src]
pub fn push_kanji_data(&mut self, data: &[u8]) -> QrResult<()>
[src]
Encodes Shift JIS double-byte data to the bits.
Errors
Returns Err(QrError::DataTooLong)
on overflow.
Returns Err(QrError::InvalidCharacter)
if the data is not Shift JIS
double-byte data (e.g. if the length of data is not an even number).
impl Bits
[src]
pub fn push_fnc1_first_position(&mut self) -> QrResult<()>
[src]
Encodes an indicator that the following data are formatted according to the UCC/EAN Application Identifiers standard.
#![allow(unused_must_use)] use qr_code::bits::Bits; use qr_code::types::Version; let mut bits = Bits::new(Version::Normal(1)); bits.push_fnc1_first_position(); bits.push_numeric_data(b"01049123451234591597033130128"); bits.push_alphanumeric_data(b"%10ABC123");
In QR code, the character %
is used as the data field separator (0x1D).
Errors
If the mode is not supported in the provided version, this method
returns Err(QrError::UnsupportedCharacterSet)
.
pub fn push_fnc1_second_position(
&mut self,
application_indicator: u8
) -> QrResult<()>
[src]
&mut self,
application_indicator: u8
) -> QrResult<()>
Encodes an indicator that the following data are formatted in accordance with specific industry or application specifications previously agreed with AIM International.
#![allow(unused_must_use)] use qr_code::bits::Bits; use qr_code::types::Version; let mut bits = Bits::new(Version::Normal(1)); bits.push_fnc1_second_position(37); bits.push_alphanumeric_data(b"AA1234BBB112"); bits.push_byte_data(b"text text text text\r");
If the application indicator is a single Latin alphabet (a–z / A–Z), please pass in its ASCII value + 100:
bits.push_fnc1_second_position(b'A' + 100);
Errors
If the mode is not supported in the provided version, this method
returns Err(QrError::UnsupportedCharacterSet)
.
impl Bits
[src]
pub fn push_terminator(&mut self, ec_level: EcLevel) -> QrResult<()>
[src]
Pushes the ending bits to indicate no more data.
Errors
Returns Err(QrError::DataTooLong)
on overflow.
Returns Err(QrError::InvalidVersion)
if it is not valid to use the
ec_level
for the given version (e.g. Version::Micro(1)
with
EcLevel::H
).
impl Bits
[src]
pub fn push_segments<I>(
&mut self,
data: &[u8],
segments_iter: I
) -> QrResult<()> where
I: Iterator<Item = Segment>,
[src]
&mut self,
data: &[u8],
segments_iter: I
) -> QrResult<()> where
I: Iterator<Item = Segment>,
Push a segmented data to the bits, and then terminate it.
Errors
Returns Err(QrError::DataTooLong)
on overflow.
Returns Err(QrError::InvalidData)
if the segment refers to incorrectly
encoded byte sequence.
pub fn push_optimal_data(&mut self, data: &[u8]) -> QrResult<()>
[src]
Pushes the data the bits, using the optimal encoding.
Errors
Returns Err(QrError::DataTooLong)
on overflow.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Bits
impl Send for Bits
impl Sync for Bits
impl Unpin for Bits
impl UnwindSafe for Bits
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,