Skip to content

Commit

Permalink
Make the inner bundle of Parented transparent
Browse files Browse the repository at this point in the history
Signed-off-by: Michael X. Grey <[email protected]>
  • Loading branch information
mxgrey committed Jan 20, 2025
1 parent a83a94b commit 3fae5da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions rmf_site_format/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ pub struct SiteID(pub u32);
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Parented<P: RefTrait, T> {
pub parent: P,
#[serde(flatten)]
pub bundle: T,
}

Expand Down
2 changes: 1 addition & 1 deletion rmf_site_format/src/sdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,6 @@ mod tests {
..Default::default()
};
let s = yaserde::ser::to_string_with_config(&sdf, &config).unwrap();
std::fs::write("test.sdf", s);
std::fs::write("test.sdf", s).unwrap();
}
}
20 changes: 20 additions & 0 deletions rmf_site_format/src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ impl Site {
serde_json::to_vec_pretty(self)
}

pub fn to_bytes_json_pretty(&self) -> serde_json::Result<Vec<u8>> {
serde_json::to_vec(self)
}

pub fn to_string_json(&self) -> serde_json::Result<String> {
serde_json::to_string(self)
}

pub fn to_string_json_pretty(&self) -> serde_json::Result<String> {
serde_json::to_string_pretty(self)
}

pub fn from_bytes_ron<'a>(s: &'a [u8]) -> ron::error::SpannedResult<Self> {
ron::de::from_bytes(s)
}
Expand Down Expand Up @@ -258,4 +270,12 @@ mod tests {
let site_string = map.to_site().unwrap().to_bytes_json().unwrap();
Site::from_bytes_json(&site_string).unwrap();
}

#[test]
fn produce_json_string() {
let data = std::fs::read("../assets/demo_maps/office.building.yaml").unwrap();
let map = BuildingMap::from_bytes(&data).unwrap();
let text = map.to_site().unwrap().to_string_json_pretty().unwrap();
println!("{text}");
}
}

0 comments on commit 3fae5da

Please sign in to comment.