feat: add a field.id
This commit is contained in:
parent
f083c696f8
commit
13254228a6
@ -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> {
|
||||
let mut carte_ps = CartePS::default();
|
||||
for group in groups {
|
||||
for (field_index, field) in group.content.iter().enumerate() {
|
||||
match (group.id, field_index + 1) {
|
||||
for field in group.content {
|
||||
match (group.id, field.id) {
|
||||
(1, 1) => {
|
||||
carte_ps.titulaire.type_de_carte_ps =
|
||||
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;
|
||||
// While there is still content to read, parse Fields
|
||||
let mut content = Vec::new();
|
||||
let mut field_id = 1;
|
||||
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_id += 1;
|
||||
content.push(field);
|
||||
}
|
||||
Block {
|
||||
@ -83,6 +86,7 @@ impl<'a> From<&'a [u8]> for Block<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Field<'a> {
|
||||
pub id: u16,
|
||||
pub size: usize,
|
||||
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 contenu = &bytes[pad..pad + size];
|
||||
Field {
|
||||
id: 0,
|
||||
size: pad + size,
|
||||
content: contenu,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user