feat: add a field.id

This commit is contained in:
Florian Briand 2024-08-02 23:02:21 +02:00
parent 4d004afc5e
commit 9126d1311b
Signed by: florian_briand
GPG Key ID: CC981B9E6B98E70B
2 changed files with 8 additions and 3 deletions

View File

@ -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();

View File

@ -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,
}