Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the inner bundle of Parented transparent #264

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rmf_site_format/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ serde_yaml = "0.8.23"
serde_json = "*"
strum = "*"
strum_macros = "*"
ron = "0.8"
# We need ron v0.9 to be released before RON works correctly for structs with #[serde(flatten)]
ron = { git = "https://github.com/ron-rs/ron", branch = "master" }
thiserror = "*"
glam = { version = "0.24", features = ["serde"] }
uuid = { version = "1.1", features = ["v4", "serde"] }
Expand Down
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
1 change: 1 addition & 0 deletions rmf_site_format/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl<T: RefTrait> OptionalModelProperty<T> {
/// Defines a property in a model description, that will be added to all instances
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "bevy", derive(Component))]
#[serde(transparent)]
pub struct OptionalModelProperties<T: RefTrait>(pub Vec<OptionalModelProperty<T>>);

impl<T: RefTrait> Default for OptionalModelProperties<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();
}
}
41 changes: 37 additions & 4 deletions rmf_site_format/src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,24 @@ fn default_style_config() -> Style {
}

impl Site {
pub fn to_writer_ron<W: io::Write>(&self, writer: W) -> ron::Result<()> {
ron::ser::to_writer_pretty(writer, self, default_style_config())
pub fn to_writer_ron<W: io::Write>(&self, mut writer: W) -> ron::Result<()> {
let mut contents = String::new();
ron::ser::to_writer_pretty(&mut contents, self, default_style_config())?;
writer
.write_all(contents.as_bytes())
.map_err(ron::Error::from)
}

pub fn to_writer_custom_ron<W: io::Write>(&self, writer: W, style: Style) -> ron::Result<()> {
ron::ser::to_writer_pretty(writer, self, style)
pub fn to_writer_custom_ron<W: io::Write>(
&self,
mut writer: W,
style: Style,
) -> ron::Result<()> {
let mut contents = String::new();
ron::ser::to_writer_pretty(&mut contents, self, style)?;
writer
.write_all(contents.as_bytes())
.map_err(ron::Error::from)
}

pub fn to_string_ron(&self) -> ron::Result<String> {
Expand Down Expand Up @@ -202,6 +214,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 @@ -248,6 +272,7 @@ mod tests {
let data = std::fs::read("../assets/demo_maps/office.building.yaml").unwrap();
let map = BuildingMap::from_bytes(&data).unwrap();
let site_string = map.to_site().unwrap().to_string_ron().unwrap();
println!("{site_string}");
Site::from_str_ron(&site_string).unwrap();
}

Expand All @@ -258,4 +283,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}");
}
}
Loading