Skip to content

Commit

Permalink
Reduce/Eliminate sdf::Model and sdf::World serialization warnings
Browse files Browse the repository at this point in the history
- Reduces serialization warnings on `sdf::Model` so it only occurs when
  the `relative_to` attribute is set. This was the intended behavior
  originally, but there was a bug in the code.
- Eliminate `sdf::World` warnings by specializing the `DefaultSerializer` for `sdf::World`.

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
  • Loading branch information
azeey committed Jan 29, 2025
1 parent 06e16bc commit e3914f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/gz/sim/components/Model.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace serializers
if (modelElem->HasElement("pose"))
{
sdf::ElementPtr poseElem = modelElem->GetElement("pose");
if (poseElem->HasAttribute("relative_to"))
if (poseElem->GetAttribute("relative_to")->GetSet())
{
// Skip serializing models with //pose/@relative_to attribute
// since deserialization will fail. This could be a nested model.
Expand Down
23 changes: 23 additions & 0 deletions include/gz/sim/components/World.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ namespace sim
{
// Inline bracket to help doxygen filtering.
inline namespace GZ_SIM_VERSION_NAMESPACE {

namespace serializers
{
/// \brief Specialize the DefaultSerializer on sdf::World so we can
/// skip serialization
/// TODO(azeey) Do we ever want to serialize this component?
template <>
class DefaultSerializer<sdf::World>
{
public:
static std::ostream &Serialize(std::ostream &_out, const sdf::World &)
{
return _out;
}

public:
static std::istream &Deserialize(std::istream &_in, sdf::World &)
{
return _in;
}
};
}

namespace components
{
/// \brief A component that identifies an entity as being a world.
Expand Down

0 comments on commit e3914f7

Please sign in to comment.