[−][src]Struct i8583::packer::Packer
i8583::Packer type and associated functions for creating iso8583 messages.
Examples
use i8583::Packer; let mut iso_packer = Packer::new(&i8583::nibss::SPEC); let pan = String::from("5432101234567898"); if let Err(msg) = iso_packer.set_field(0, "0200".as_bytes().into()) { eprintln!("{}", msg); return; } if let Err(msg) = iso_packer.set_field(2, pan.into_bytes().into()) { eprintln!("{}", msg); return; } let iso = match iso_packer.pack(Vec::with_capacity(1024)) { Ok(iso) => iso, Err(msg) => { eprintln!("{}", msg); return; } }; let iso = String::from_utf8(iso).unwrap(); println!("{}", iso);
Implementations
impl<'a> Packer<'a>
[src]
pub fn new(spec: &'a [Option<Spec>; 129]) -> Packer
[src]
Create a new packer with the given iso specification. The provided spec will be used to validate set_field inputs
pub fn toggle_bit_64(&mut self, val: bool)
[src]
Manually set bit 64 to on or off.
Rationale
Message authentication codes (MAC) can only be generated after obtaining a full iso 8583 message, this function provides a way to indicate the presence of a MAC in the bitmap while defering the computation and addition of the actual message authentication code.
Warning
Do not set both toggle_bit_64 and toggle_bit_128 to on.
Use of this function to set bit 64 to on will render pack output bitmap incorrect, a MAC must be appended to re-establish correctness.
pub fn toggle_bit_128(&mut self, val: bool)
[src]
Manually set bit 128 to on or off.
Rationale
Message authentication codes (MAC) can only be generated after obtaining a full iso 8583 message, this function provides a way to indicate the presence of a MAC in the bitmap while defering the computation and addition of the actual message authentication code.
Warning
Do not set both toggle_bit_64 and toggle_bit_128 to on.
Use of this function to set bit 128 to on will render pack output bitmap incorrect, a MAC must be appended to re-establish correctness.
pub fn set_field(
&mut self,
field: usize,
val: Cow<'a, [u8]>
) -> Result<(), String>
[src]
&mut self,
field: usize,
val: Cow<'a, [u8]>
) -> Result<(), String>
Set val for field in iso message. This will replace existing value if previously set
Errors
Will fail if specification is not found for field or val size is invalid
pub fn unset_field(&mut self, field: usize)
[src]
Unset val for field in iso message.
pub fn pack(&self, buffer: Vec<u8>) -> Result<Vec<u8>, &'static str>
[src]
Generate iso message. Call this function after setting all fields
Errors
Will fail if MTI(field 0) is not set
Auto Trait Implementations
impl<'a> RefUnwindSafe for Packer<'a>
impl<'a> Send for Packer<'a>
impl<'a> Sync for Packer<'a>
impl<'a> Unpin for Packer<'a>
impl<'a> UnwindSafe for Packer<'a>
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, 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>,