Ajout de la lecture de carte CPS dans le moteur SESAM-Vitale #29

Merged
florian_briand merged 11 commits from feature_ssv_lire_carte_ps into main 2024-08-03 14:57:58 +02:00
2 changed files with 8 additions and 3 deletions
Showing only changes of commit 9126d1311b - Show all commits

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> { 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();
florian_briand marked this conversation as resolved
Review
  • Stocker l'index du champ dans l'objet field, il est structurel et on en aura besoin plus tard
- [x] Stocker l'index du champ dans l'objet `field`, il est structurel et on en aura besoin plus tard

View File

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