Indices — componentType 5121 (u8), 5123 (u16), or 5125 (u32). Always returned as u32.
(
accessors: &[JVal], buf_views: &[JVal], bin: &[u8], acc_idx: usize,
)
| 530 | /// Indices — componentType 5121 (u8), 5123 (u16), or 5125 (u32). Always |
| 531 | /// returned as u32. |
| 532 | fn read_index_vec( |
| 533 | accessors: &[JVal], buf_views: &[JVal], bin: &[u8], acc_idx: usize, |
| 534 | ) -> Option<Vec<u32>> { |
| 535 | let acc = accessors.get(acc_idx)?; |
| 536 | let comp_type = acc.get("componentType")?.num()? as u32; |
| 537 | let bv_idx = acc.get("bufferView")?.num()? as usize; |
| 538 | let count = acc.get("count")?.num()? as usize; |
| 539 | let byte_off_acc = acc.get("byteOffset").and_then(|v| v.num()).unwrap_or(0.0) as usize; |
| 540 | |
| 541 | let bv = buf_views.get(bv_idx)?; |
| 542 | let byte_off_bv = bv.get("byteOffset").and_then(|v| v.num()).unwrap_or(0.0) as usize; |
| 543 | let base = byte_off_bv + byte_off_acc; |
| 544 | |
| 545 | let mut out = Vec::with_capacity(count); |
| 546 | match comp_type { |
| 547 | 5121 => { // u8 |
| 548 | if base + count > bin.len() { return None; } |
| 549 | for i in 0..count { out.push(bin[base + i] as u32); } |
| 550 | } |
| 551 | 5123 => { // u16 |
| 552 | if base + count * 2 > bin.len() { return None; } |
| 553 | for i in 0..count { |
| 554 | let o = base + i * 2; |
| 555 | out.push(u16::from_le_bytes([bin[o], bin[o+1]]) as u32); |
| 556 | } |
| 557 | } |
| 558 | 5125 => { // u32 |
| 559 | if base + count * 4 > bin.len() { return None; } |
| 560 | for i in 0..count { |
| 561 | let o = base + i * 4; |
| 562 | out.push(u32::from_le_bytes([bin[o], bin[o+1], bin[o+2], bin[o+3]])); |
| 563 | } |
| 564 | } |
| 565 | _ => return None, |
| 566 | } |
| 567 | Some(out) |
| 568 | } |
| 569 | |
| 570 | // ---------- Tiny JSON value parser ---------- |
| 571 | // |
no test coverage detected