feat: add a field.id
This commit is contained in:
parent
4d004afc5e
commit
9126d1311b
@ -82,8 +82,8 @@ pub fn lire_carte(code_pin: &str, lecteur: &str) -> Result<CartePS, String> {
|
|||||||
fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
|
fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
|
||||||
let mut carte_ps = CartePS::default();
|
let mut carte_ps = CartePS::default();
|
||||||
for group in groups {
|
for group in groups {
|
||||||
for (field_index, field) in group.content.iter().enumerate() {
|
for field in group.content {
|
||||||
match (group.id, field_index + 1) {
|
match (group.id, field.id) {
|
||||||
(1, 1) => {
|
(1, 1) => {
|
||||||
carte_ps.titulaire.type_de_carte_ps =
|
carte_ps.titulaire.type_de_carte_ps =
|
||||||
String::from_utf8_lossy(field.content).to_string();
|
String::from_utf8_lossy(field.content).to_string();
|
||||||
|
@ -68,9 +68,12 @@ impl<'a> From<&'a [u8]> for Block<'a> {
|
|||||||
let mut field_offset = 0;
|
let mut field_offset = 0;
|
||||||
// While there is still content to read, parse Fields
|
// While there is still content to read, parse Fields
|
||||||
let mut content = Vec::new();
|
let mut content = Vec::new();
|
||||||
|
let mut field_id = 1;
|
||||||
while field_offset < block_size {
|
while field_offset < block_size {
|
||||||
let field: Field<'a> = raw_content[field_offset..].into();
|
let mut field: Field<'a> = raw_content[field_offset..].into();
|
||||||
|
field.id = field_id;
|
||||||
field_offset += field.size;
|
field_offset += field.size;
|
||||||
|
field_id += 1;
|
||||||
content.push(field);
|
content.push(field);
|
||||||
}
|
}
|
||||||
Block {
|
Block {
|
||||||
@ -83,6 +86,7 @@ impl<'a> From<&'a [u8]> for Block<'a> {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Field<'a> {
|
pub struct Field<'a> {
|
||||||
|
pub id: u16,
|
||||||
pub size: usize,
|
pub size: usize,
|
||||||
pub content: &'a [u8],
|
pub content: &'a [u8],
|
||||||
}
|
}
|
||||||
@ -92,6 +96,7 @@ impl<'a> From<&'a [u8]> for Field<'a> {
|
|||||||
let ElementSize { size, pad } = bytes.try_into().unwrap();
|
let ElementSize { size, pad } = bytes.try_into().unwrap();
|
||||||
let contenu = &bytes[pad..pad + size];
|
let contenu = &bytes[pad..pad + size];
|
||||||
Field {
|
Field {
|
||||||
|
id: 0,
|
||||||
size: pad + size,
|
size: pad + size,
|
||||||
content: contenu,
|
content: contenu,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user