add check sort

This commit is contained in:
Jean-Marie Mineau 2023-08-25 11:30:09 +02:00
parent d5b8222491
commit 736c4611ac
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
3 changed files with 16 additions and 1 deletions

View file

@ -56,6 +56,18 @@ impl Serializable for EncodedAnnotation {
for _ in 0..size {
elements.push(AnnotationElement::deserialize(input)?);
}
if !elements.is_empty() {
let mut idx_0 = elements[0].name_idx;
for idx_1 in elements.iter().map(|elt| elt.name_idx).skip(1) {
if idx_0 > idx_1 {
// TODO: use proper logging
println!(
"Waring while deserializing EncodedAnnotation: element must be sorted in increasing order by string_id index, found {idx_0:?} before {idx_1:?}"
);
}
idx_0 = idx_1;
}
}
Ok(Self { type_idx, elements })
}