Skip to content

Commit 76467bc

Browse files
authored
Move Rust API unit tests to a separate directory (#1227)
### Summary - Ticket no. 127586 - It comes from this feedback, #1224 (comment). ### How to test ```console $ cd rust $ cargo test ``` ### Checklist <!-- Put an 'x' in all the boxes that apply --> - [ ] I have added unit tests to cover my changes.​ - [ ] I have added integration tests to cover my changes.​ - [ ] I have added the description of my changes into [CHANGELOG](https://github.com/openvinotoolkit/datumaro/blob/develop/CHANGELOG.md).​ - [ ] I have updated the [documentation](https://github.com/openvinotoolkit/datumaro/tree/develop/docs) accordingly ### License - [x] I submit _my code changes_ under the same [MIT License](https://github.com/openvinotoolkit/datumaro/blob/develop/LICENSE) that covers the project. Feel free to contact the maintainers if that's a concern. - [x] I have updated the license header for each file (see an example below). ```python # Copyright (C) 2023 Intel Corporation # # SPDX-License-Identifier: MIT ``` Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
1 parent 044b705 commit 76467bc

8 files changed

+149
-145
lines changed

rust/src/coco_page_mapper.rs

+1-76
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl ParsedJsonSection for CocoJsonSection {
7575
}
7676

7777
#[derive(Debug)]
78-
struct CocoPageMapperImpl {
78+
pub struct CocoPageMapperImpl {
7979
licenses: JsonDict,
8080
info: JsonDict,
8181
categories: JsonDict,
@@ -211,78 +211,3 @@ impl CocoPageMapper {
211211
Ok(self.mapper.get_img_ids().len())
212212
}
213213
}
214-
215-
#[cfg(test)]
216-
mod tests {
217-
use super::*;
218-
use crate::test_helpers::prepare_reader;
219-
220-
#[test]
221-
fn test_instance() {
222-
const EXAMPLE: &str = r#"
223-
{
224-
"licenses":[{"name":"test_instance()","id":0,"url":""}],
225-
"info":{"contributor":"","date_created":"","description":"","url":"","version":"","year":""},
226-
"categories":[
227-
{"id":1,"name":"a","supercategory":""},
228-
{"id":2,"name":"b","supercategory":""},
229-
{"id":4,"name":"c","supercategory":""}
230-
],
231-
"images":[
232-
{"id":5,"width":10,"height":5,"file_name":"a.jpg","license":0,"flickr_url":"","coco_url":"","date_captured":0},
233-
{"id":6,"width":10,"height":5,"file_name":"b.jpg","license":0,"flickr_url":"","coco_url":"","date_captured":0}
234-
],
235-
"annotations":[
236-
{"id":1,"image_id":5,"category_id":2,"segmentation":[],"area":3.0,"bbox":[2.0,2.0,3.0,1.0],"iscrowd":0},
237-
{"id":2,"image_id":5,"category_id":2,"segmentation":[],"area":3.0,"bbox":[2.0,2.0,3.0,1.0],"iscrowd":0},
238-
{"id":3,"image_id":5,"category_id":2,"segmentation":[],"area":3.0,"bbox":[2.0,2.0,3.0,1.0],"iscrowd":0},
239-
{"id":4,"image_id":6,"category_id":2,"segmentation":[],"area":3.0,"bbox":[2.0,2.0,3.0,1.0],"iscrowd":0},
240-
{"id":5,"image_id":6,"category_id":2,"segmentation":[],"area":3.0,"bbox":[2.0,2.0,3.0,1.0],"iscrowd":0}
241-
]
242-
}"#;
243-
244-
let (tempfile, mut reader) = prepare_reader(EXAMPLE);
245-
let coco_page_mapper = CocoPageMapperImpl::new(&mut reader).unwrap();
246-
247-
println!("{:?}", coco_page_mapper);
248-
249-
for img_id in [5, 6] {
250-
let item = coco_page_mapper
251-
.get_item_dict(&img_id, &mut reader)
252-
.unwrap();
253-
254-
assert_eq!(item["id"].as_i64(), Some(img_id));
255-
256-
let anns = coco_page_mapper.get_anns_dict(img_id, &mut reader).unwrap();
257-
assert!(anns.len() > 0);
258-
259-
for ann in anns {
260-
assert_eq!(ann["image_id"].as_i64(), Some(img_id));
261-
}
262-
}
263-
}
264-
265-
#[test]
266-
fn test_image_info_default() {
267-
const EXAMPLE: &str = r#"
268-
{"licenses": [{"name": "", "id": 0, "url": ""}], "info": {"contributor": "", "date_created": "", "description": "", "url": "", "version": "", "year": ""}, "categories": [], "images": [{"id": 1, "width": 2, "height": 4, "file_name": "1.jpg", "license": 0, "flickr_url": "", "coco_url": "", "date_captured": 0}], "annotations": []}
269-
"#;
270-
271-
let (tempfile, mut reader) = prepare_reader(EXAMPLE);
272-
let coco_page_mapper = CocoPageMapperImpl::new(&mut reader).unwrap();
273-
274-
println!("{:?}", coco_page_mapper);
275-
}
276-
277-
#[test]
278-
fn test_panoptic_has_no_ann_id() {
279-
const EXAMPLE: &str = r#"
280-
{"licenses":[{"name":"","id":0,"url":""}],"info":{"contributor":"","date_created":"","description":"","url":"","version":"","year":""},"categories":[{"id":1,"name":"0","supercategory":"","isthing":0},{"id":2,"name":"1","supercategory":"","isthing":0},{"id":3,"name":"2","supercategory":"","isthing":0},{"id":4,"name":"3","supercategory":"","isthing":0},{"id":5,"name":"4","supercategory":"","isthing":0},{"id":6,"name":"5","supercategory":"","isthing":0},{"id":7,"name":"6","supercategory":"","isthing":0},{"id":8,"name":"7","supercategory":"","isthing":0},{"id":9,"name":"8","supercategory":"","isthing":0},{"id":10,"name":"9","supercategory":"","isthing":0}],"images":[{"id":1,"width":4,"height":4,"file_name":"1.jpg","license":0,"flickr_url":"","coco_url":"","date_captured":0}],"annotations":[{"image_id":1,"file_name":"1.png","segments_info":[{"id":3,"category_id":5,"area":5.0,"bbox":[1.0,0.0,2.0,2.0],"iscrowd":0}]}]}
281-
"#;
282-
283-
let (tempfile, mut reader) = prepare_reader(EXAMPLE);
284-
let coco_page_mapper = CocoPageMapperImpl::new(&mut reader).unwrap();
285-
286-
println!("{:?}", coco_page_mapper);
287-
}
288-
}

rust/src/datum_page_mapper.rs

-29
Original file line numberDiff line numberDiff line change
@@ -205,32 +205,3 @@ impl DatumPageMapper {
205205
Ok(self.mapper.get_img_ids().len())
206206
}
207207
}
208-
209-
#[cfg(test)]
210-
mod tests {
211-
use super::*;
212-
use crate::test_helpers::prepare_reader;
213-
214-
#[test]
215-
fn test_instance() {
216-
const EXAMPLE: &str = r#"{"dm_format_version": "1.0", "media_type": 2, "infos": {"string": "test", "int": 0, "float": 0.0, "string_list": ["test0", "test1", "test2"], "int_list": [0, 1, 2], "float_list": [0.0, 0.1, 0.2]}, "categories": {"label": {"labels": [{"name": "cat0", "parent": "", "attributes": ["x", "y"]}, {"name": "cat1", "parent": "", "attributes": ["x", "y"]}, {"name": "cat2", "parent": "", "attributes": ["x", "y"]}, {"name": "cat3", "parent": "", "attributes": ["x", "y"]}, {"name": "cat4", "parent": "", "attributes": ["x", "y"]}], "label_groups": [], "attributes": ["a", "b", "score"]}, "mask": {"colormap": [{"label_id": 0, "r": 0, "g": 0, "b": 0}, {"label_id": 1, "r": 128, "g": 0, "b": 0}, {"label_id": 2, "r": 0, "g": 128, "b": 0}, {"label_id": 3, "r": 128, "g": 128, "b": 0}, {"label_id": 4, "r": 0, "g": 0, "b": 128}]}, "points": {"items": [{"label_id": 0, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 1, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 2, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 3, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 4, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}]}}, "items": [{"id": "42", "annotations": [{"id": 900100087038, "type": "mask", "attributes": {}, "group": 900100087038, "label_id": null, "rle": {"counts": "06", "size": [2, 3]}, "z_order": 0}, {"id": 900100087038, "type": "mask", "attributes": {}, "group": 900100087038, "label_id": null, "rle": {"counts": "06", "size": [2, 3]}, "z_order": 0}], "image": {"path": "42.jpg", "size": [10, 6]}}, {"id": "43", "annotations": [], "image": {"path": "43.qq", "size": [2, 4]}}]}
217-
"#;
218-
219-
let (tempfile, mut reader) = prepare_reader(EXAMPLE);
220-
let datum_page_mapper = DatumPageMapperImpl::new(&mut reader).unwrap();
221-
222-
println!("{:?}", datum_page_mapper);
223-
224-
let expected_ids = vec!["42".to_string(), "43".to_string()];
225-
assert_eq!(datum_page_mapper.get_img_ids(), &expected_ids);
226-
227-
for img_id in expected_ids {
228-
let item = datum_page_mapper
229-
.get_item_dict(&img_id.to_string(), &mut reader)
230-
.unwrap();
231-
232-
assert_eq!(item["id"].as_str(), Some(img_id.as_str()));
233-
println!("{:?}", item);
234-
}
235-
}
236-
}

rust/src/json_section_page_mapper.rs

+5-36
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use std::{
1515
};
1616

1717
#[derive(Debug)]
18-
struct JsonSection {
19-
key: String,
20-
offset: usize,
21-
size: usize,
18+
pub struct JsonSection {
19+
pub key: String,
20+
pub offset: usize,
21+
pub size: usize,
2222
}
2323

2424
fn handle_arr_or_dict(
@@ -150,7 +150,7 @@ impl ParsedJsonSection for JsonSection {
150150

151151
#[derive(Debug)]
152152
pub struct JsonSectionPageMapperImpl {
153-
sections: Vec<Box<JsonSection>>,
153+
pub sections: Vec<Box<JsonSection>>,
154154
}
155155

156156
impl JsonPageMapper<JsonSection> for JsonSectionPageMapperImpl {}
@@ -199,34 +199,3 @@ impl JsonSectionPageMapper {
199199
Ok(self.mapper.sections.len())
200200
}
201201
}
202-
203-
#[cfg(test)]
204-
mod tests {
205-
use super::*;
206-
use crate::test_helpers::prepare_reader;
207-
208-
#[test]
209-
fn test_instance() {
210-
const EXAMPLE: &str = r#"{"dm_format_version": "1.0", "media_type": 2, "infos": {"string": "test", "int": 0, "float": 0.0, "string_list": ["test0", "test1", "test2"], "int_list": [0, 1, 2], "float_list": [0.0, 0.1, 0.2]}, "categories": {"label": {"labels": [{"name": "cat0", "parent": "", "attributes": ["x", "y"]}, {"name": "cat1", "parent": "", "attributes": ["x", "y"]}, {"name": "cat2", "parent": "", "attributes": ["x", "y"]}, {"name": "cat3", "parent": "", "attributes": ["x", "y"]}, {"name": "cat4", "parent": "", "attributes": ["x", "y"]}], "label_groups": [], "attributes": ["a", "b", "score"]}, "mask": {"colormap": [{"label_id": 0, "r": 0, "g": 0, "b": 0}, {"label_id": 1, "r": 128, "g": 0, "b": 0}, {"label_id": 2, "r": 0, "g": 128, "b": 0}, {"label_id": 3, "r": 128, "g": 128, "b": 0}, {"label_id": 4, "r": 0, "g": 0, "b": 128}]}, "points": {"items": [{"label_id": 0, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 1, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 2, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 3, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 4, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}]}}, "items": [{"id": "42", "annotations": [{"id": 900100087038, "type": "mask", "attributes": {}, "group": 900100087038, "label_id": null, "rle": {"counts": "06", "size": [2, 3]}, "z_order": 0}, {"id": 900100087038, "type": "mask", "attributes": {}, "group": 900100087038, "label_id": null, "rle": {"counts": "06", "size": [2, 3]}, "z_order": 0}], "image": {"path": "42.jpg", "size": [10, 6]}}, {"id": "43", "annotations": [], "image": {"path": "43.qq", "size": [2, 4]}}]}
211-
"#;
212-
213-
let (tempfile, mut reader) = prepare_reader(EXAMPLE);
214-
let json_section_page_mapper = JsonSectionPageMapperImpl::new(&mut reader).unwrap();
215-
216-
println!("{:?}", json_section_page_mapper);
217-
218-
for section in json_section_page_mapper.sections {
219-
let offset = section.offset;
220-
let size = section.size;
221-
reader.seek(io::SeekFrom::Start(offset as u64));
222-
let mut buf = vec![0; size];
223-
reader.read(buf.as_mut_slice());
224-
225-
let content: serde_json::Value = serde_json::from_str(
226-
std::str::from_utf8(buf.as_slice()).expect("Cannot change to utf8"),
227-
)
228-
.unwrap();
229-
println!("Section: {}, Content: {:?}", section.key, content);
230-
}
231-
}
232-
}

rust/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
//
33
// SPDX-License-Identifier: MIT
44

5-
mod coco_page_mapper;
6-
mod datum_page_mapper;
7-
mod json_section_page_mapper;
5+
pub mod coco_page_mapper;
6+
pub mod datum_page_mapper;
7+
pub mod json_section_page_mapper;
88
mod page_mapper;
99
mod page_maps;
10-
mod test_helpers;
1110
mod utils;
1211
use pyo3::prelude::*;
1312

rust/tests/coco_page_mapper.rs

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (C) 2023 Intel Corporation
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
mod test_helpers;
6+
7+
use datumaro_rust_api::coco_page_mapper::CocoPageMapperImpl;
8+
use test_helpers::prepare_reader;
9+
10+
#[test]
11+
fn test_instance() {
12+
const EXAMPLE: &str = r#"
13+
{
14+
"licenses":[{"name":"test_instance()","id":0,"url":""}],
15+
"info":{"contributor":"","date_created":"","description":"","url":"","version":"","year":""},
16+
"categories":[
17+
{"id":1,"name":"a","supercategory":""},
18+
{"id":2,"name":"b","supercategory":""},
19+
{"id":4,"name":"c","supercategory":""}
20+
],
21+
"images":[
22+
{"id":5,"width":10,"height":5,"file_name":"a.jpg","license":0,"flickr_url":"","coco_url":"","date_captured":0},
23+
{"id":6,"width":10,"height":5,"file_name":"b.jpg","license":0,"flickr_url":"","coco_url":"","date_captured":0}
24+
],
25+
"annotations":[
26+
{"id":1,"image_id":5,"category_id":2,"segmentation":[],"area":3.0,"bbox":[2.0,2.0,3.0,1.0],"iscrowd":0},
27+
{"id":2,"image_id":5,"category_id":2,"segmentation":[],"area":3.0,"bbox":[2.0,2.0,3.0,1.0],"iscrowd":0},
28+
{"id":3,"image_id":5,"category_id":2,"segmentation":[],"area":3.0,"bbox":[2.0,2.0,3.0,1.0],"iscrowd":0},
29+
{"id":4,"image_id":6,"category_id":2,"segmentation":[],"area":3.0,"bbox":[2.0,2.0,3.0,1.0],"iscrowd":0},
30+
{"id":5,"image_id":6,"category_id":2,"segmentation":[],"area":3.0,"bbox":[2.0,2.0,3.0,1.0],"iscrowd":0}
31+
]
32+
}"#;
33+
34+
let (tempfile, mut reader) = prepare_reader(EXAMPLE);
35+
let coco_page_mapper = CocoPageMapperImpl::new(&mut reader).unwrap();
36+
37+
println!("{:?}", coco_page_mapper);
38+
39+
for img_id in [5, 6] {
40+
let item = coco_page_mapper
41+
.get_item_dict(&img_id, &mut reader)
42+
.unwrap();
43+
44+
assert_eq!(item["id"].as_i64(), Some(img_id));
45+
46+
let anns = coco_page_mapper.get_anns_dict(img_id, &mut reader).unwrap();
47+
assert!(anns.len() > 0);
48+
49+
for ann in anns {
50+
assert_eq!(ann["image_id"].as_i64(), Some(img_id));
51+
}
52+
}
53+
}
54+
55+
#[test]
56+
fn test_image_info_default() {
57+
const EXAMPLE: &str = r#"
58+
{"licenses": [{"name": "", "id": 0, "url": ""}], "info": {"contributor": "", "date_created": "", "description": "", "url": "", "version": "", "year": ""}, "categories": [], "images": [{"id": 1, "width": 2, "height": 4, "file_name": "1.jpg", "license": 0, "flickr_url": "", "coco_url": "", "date_captured": 0}], "annotations": []}
59+
"#;
60+
61+
let (tempfile, mut reader) = prepare_reader(EXAMPLE);
62+
let coco_page_mapper = CocoPageMapperImpl::new(&mut reader).unwrap();
63+
64+
println!("{:?}", coco_page_mapper);
65+
}
66+
67+
#[test]
68+
fn test_panoptic_has_no_ann_id() {
69+
const EXAMPLE: &str = r#"
70+
{"licenses":[{"name":"","id":0,"url":""}],"info":{"contributor":"","date_created":"","description":"","url":"","version":"","year":""},"categories":[{"id":1,"name":"0","supercategory":"","isthing":0},{"id":2,"name":"1","supercategory":"","isthing":0},{"id":3,"name":"2","supercategory":"","isthing":0},{"id":4,"name":"3","supercategory":"","isthing":0},{"id":5,"name":"4","supercategory":"","isthing":0},{"id":6,"name":"5","supercategory":"","isthing":0},{"id":7,"name":"6","supercategory":"","isthing":0},{"id":8,"name":"7","supercategory":"","isthing":0},{"id":9,"name":"8","supercategory":"","isthing":0},{"id":10,"name":"9","supercategory":"","isthing":0}],"images":[{"id":1,"width":4,"height":4,"file_name":"1.jpg","license":0,"flickr_url":"","coco_url":"","date_captured":0}],"annotations":[{"image_id":1,"file_name":"1.png","segments_info":[{"id":3,"category_id":5,"area":5.0,"bbox":[1.0,0.0,2.0,2.0],"iscrowd":0}]}]}
71+
"#;
72+
73+
let (tempfile, mut reader) = prepare_reader(EXAMPLE);
74+
let coco_page_mapper = CocoPageMapperImpl::new(&mut reader).unwrap();
75+
76+
println!("{:?}", coco_page_mapper);
77+
}

rust/tests/datum_page_mapper.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2023 Intel Corporation
2+
//
3+
// SPDX-License-Identifier: MIT
4+
mod test_helpers;
5+
6+
use datumaro_rust_api::datum_page_mapper::DatumPageMapperImpl;
7+
use test_helpers::prepare_reader;
8+
9+
#[test]
10+
fn test_instance() {
11+
const EXAMPLE: &str = r#"{"dm_format_version": "1.0", "media_type": 2, "infos": {"string": "test", "int": 0, "float": 0.0, "string_list": ["test0", "test1", "test2"], "int_list": [0, 1, 2], "float_list": [0.0, 0.1, 0.2]}, "categories": {"label": {"labels": [{"name": "cat0", "parent": "", "attributes": ["x", "y"]}, {"name": "cat1", "parent": "", "attributes": ["x", "y"]}, {"name": "cat2", "parent": "", "attributes": ["x", "y"]}, {"name": "cat3", "parent": "", "attributes": ["x", "y"]}, {"name": "cat4", "parent": "", "attributes": ["x", "y"]}], "label_groups": [], "attributes": ["a", "b", "score"]}, "mask": {"colormap": [{"label_id": 0, "r": 0, "g": 0, "b": 0}, {"label_id": 1, "r": 128, "g": 0, "b": 0}, {"label_id": 2, "r": 0, "g": 128, "b": 0}, {"label_id": 3, "r": 128, "g": 128, "b": 0}, {"label_id": 4, "r": 0, "g": 0, "b": 128}]}, "points": {"items": [{"label_id": 0, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 1, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 2, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 3, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 4, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}]}}, "items": [{"id": "42", "annotations": [{"id": 900100087038, "type": "mask", "attributes": {}, "group": 900100087038, "label_id": null, "rle": {"counts": "06", "size": [2, 3]}, "z_order": 0}, {"id": 900100087038, "type": "mask", "attributes": {}, "group": 900100087038, "label_id": null, "rle": {"counts": "06", "size": [2, 3]}, "z_order": 0}], "image": {"path": "42.jpg", "size": [10, 6]}}, {"id": "43", "annotations": [], "image": {"path": "43.qq", "size": [2, 4]}}]}
12+
"#;
13+
14+
let (tempfile, mut reader) = prepare_reader(EXAMPLE);
15+
let datum_page_mapper = DatumPageMapperImpl::new(&mut reader).unwrap();
16+
17+
println!("{:?}", datum_page_mapper);
18+
19+
let expected_ids = vec!["42".to_string(), "43".to_string()];
20+
assert_eq!(datum_page_mapper.get_img_ids(), &expected_ids);
21+
22+
for img_id in expected_ids {
23+
let item = datum_page_mapper
24+
.get_item_dict(&img_id.to_string(), &mut reader)
25+
.unwrap();
26+
27+
assert_eq!(item["id"].as_str(), Some(img_id.as_str()));
28+
println!("{:?}", item);
29+
}
30+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (C) 2023 Intel Corporation
2+
//
3+
// SPDX-License-Identifier: MIT
4+
mod test_helpers;
5+
6+
use std::io::{self, Seek, Read};
7+
use datumaro_rust_api::json_section_page_mapper::JsonSectionPageMapperImpl;
8+
use test_helpers::prepare_reader;
9+
10+
#[test]
11+
fn test_instance() {
12+
const EXAMPLE: &str = r#"{"dm_format_version": "1.0", "media_type": 2, "infos": {"string": "test", "int": 0, "float": 0.0, "string_list": ["test0", "test1", "test2"], "int_list": [0, 1, 2], "float_list": [0.0, 0.1, 0.2]}, "categories": {"label": {"labels": [{"name": "cat0", "parent": "", "attributes": ["x", "y"]}, {"name": "cat1", "parent": "", "attributes": ["x", "y"]}, {"name": "cat2", "parent": "", "attributes": ["x", "y"]}, {"name": "cat3", "parent": "", "attributes": ["x", "y"]}, {"name": "cat4", "parent": "", "attributes": ["x", "y"]}], "label_groups": [], "attributes": ["a", "b", "score"]}, "mask": {"colormap": [{"label_id": 0, "r": 0, "g": 0, "b": 0}, {"label_id": 1, "r": 128, "g": 0, "b": 0}, {"label_id": 2, "r": 0, "g": 128, "b": 0}, {"label_id": 3, "r": 128, "g": 128, "b": 0}, {"label_id": 4, "r": 0, "g": 0, "b": 128}]}, "points": {"items": [{"label_id": 0, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 1, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 2, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 3, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}, {"label_id": 4, "labels": ["cat1", "cat2"], "joints": [[0, 1]]}]}}, "items": [{"id": "42", "annotations": [{"id": 900100087038, "type": "mask", "attributes": {}, "group": 900100087038, "label_id": null, "rle": {"counts": "06", "size": [2, 3]}, "z_order": 0}, {"id": 900100087038, "type": "mask", "attributes": {}, "group": 900100087038, "label_id": null, "rle": {"counts": "06", "size": [2, 3]}, "z_order": 0}], "image": {"path": "42.jpg", "size": [10, 6]}}, {"id": "43", "annotations": [], "image": {"path": "43.qq", "size": [2, 4]}}]}
13+
"#;
14+
15+
let (tempfile, mut reader) = prepare_reader(EXAMPLE);
16+
let json_section_page_mapper = JsonSectionPageMapperImpl::new(&mut reader).unwrap();
17+
18+
println!("{:?}", json_section_page_mapper);
19+
20+
for section in json_section_page_mapper.sections {
21+
let offset = section.offset;
22+
let size = section.size;
23+
reader.seek(io::SeekFrom::Start(offset as u64));
24+
let mut buf = vec![0; size];
25+
reader.read(buf.as_mut_slice());
26+
27+
let content: serde_json::Value = serde_json::from_str(
28+
std::str::from_utf8(buf.as_slice()).expect("Cannot change to utf8"),
29+
)
30+
.unwrap();
31+
println!("Section: {}, Content: {:?}", section.key, content);
32+
}
33+
}
File renamed without changes.

0 commit comments

Comments
 (0)