OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Serialization differences between ASCII and XML


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
hartwigw
Appreciator


Joined: 20 Mar 2009
Posts: 128

PostPosted: Wed Dec 27, 2017 5:49 pm    Post subject:
Serialization differences between ASCII and XML
Reply with quote

Hi,

wrote a simple serialiser for the output of a range:

Code:

namespace
{
   bool checkGeographicRange(osgPlanetCore::GeodeticData const&)
   {
      return true;
   }

   bool readGeographicRange(osgDB::InputStream& inputStream, osgPlanetCore::GeodeticData& geodeticData)
   {
      osgPlanetCore::GeographicRange geographicRange;


      if (osgPlanetWrappers::readRange(inputStream,geographicRange))
      {
         geodeticData.setGeographicRange(geographicRange);
         return true;
      } /* if */
      else
         return false;
   }
   
   bool writeGeographicRange(osgDB::OutputStream& outputStream, osgPlanetCore::GeodeticData const& geodeticData)
   {
      outputStream << std::endl;
      return osgPlanetWrappers::writeRange(outputStream,geodeticData.getGeographicRange());
   }

} /* namespace */

   template < typename Values >
   bool readRange(osgDB::InputStream& inputStream, osgPlanetCore::Range< Values >& range)
   {
      inputStream >> inputStream.BEGIN_BRACKET;
      inputStream >> inputStream.PROPERTY("FromValues") >> range.getFromValues();
      inputStream >> inputStream.PROPERTY("TillValues") >> range.getTillValues();
      inputStream >> inputStream.END_BRACKET;
      return true;
   }
   
   template < typename Values >
   bool writeRange(osgDB::OutputStream& outputStream, osgPlanetCore::Range< Values > const& range)
   {
      outputStream << outputStream.BEGIN_BRACKET << std::endl;
      outputStream << outputStream.PROPERTY("FromValues") << range.getFromValues() << std::endl;
      outputStream << outputStream.PROPERTY("TillValues") << range.getTillValues() << std::endl;
      outputStream << outputStream.END_BRACKET << std::endl;
      return true;
   }



In a wrapper I call
Code:

   ADD_USER_SERIALIZER(GeographicRange);


Basically serialisation should write / read two vectors indicating a lower and a higher limit of a geodetic range.

The ASCII output looks like:

GeographicRange
{
FromValues -135 40.9799 -10000
TillValues -90 66.5133 10000
}

Which seems to be fine.

The XML output looks like:

< FromValues attribute="-135 40.9799 -10000&nl;" >
< TillValues attribute="-90 66.5133 10000&nl;&nl;" >
< /TillValues >
< /FromValues >

Which is not really the same. Besides the fact that "GeographicRange" is gone completely.

How do I make the output of both versions the same?

Cheers,
Hartwig
Back to top
View user's profile Send private message
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 475
Location: France

PostPosted: Thu Dec 28, 2017 6:51 pm    Post subject:
Re: Serialization differences between ASCII and XML
Reply with quote

Hi Hartwig
I have no experience with osgx format
But the bug seams to come from osgDB/XMLParser.cpp
perhaps removing newline (with trimEnclosingSpaces) from strings in osgDB::XMLNode::writeString
could to the trick...
or better add newline in _characterToControlMap

You should make a pull request for this bug fix

Cheers

hartwigw wrote:
Hi,

wrote a simple serialiser for the output of a range:

Code:

namespace
{
   bool checkGeographicRange(osgPlanetCore::GeodeticData const&)
   {
      return true;
   }

   bool readGeographicRange(osgDB::InputStream& inputStream, osgPlanetCore::GeodeticData& geodeticData)
   {
      osgPlanetCore::GeographicRange geographicRange;


      if (osgPlanetWrappers::readRange(inputStream,geographicRange))
      {
         geodeticData.setGeographicRange(geographicRange);
         return true;
      } /* if */
      else
         return false;
   }
   
   bool writeGeographicRange(osgDB::OutputStream& outputStream, osgPlanetCore::GeodeticData const& geodeticData)
   {
      outputStream << std::endl;
      return osgPlanetWrappers::writeRange(outputStream,geodeticData.getGeographicRange());
   }

} /* namespace */

   template < typename Values >
   bool readRange(osgDB::InputStream& inputStream, osgPlanetCore::Range< Values >& range)
   {
      inputStream >> inputStream.BEGIN_BRACKET;
      inputStream >> inputStream.PROPERTY("FromValues") >> range.getFromValues();
      inputStream >> inputStream.PROPERTY("TillValues") >> range.getTillValues();
      inputStream >> inputStream.END_BRACKET;
      return true;
   }
   
   template < typename Values >
   bool writeRange(osgDB::OutputStream& outputStream, osgPlanetCore::Range< Values > const& range)
   {
      outputStream << outputStream.BEGIN_BRACKET << std::endl;
      outputStream << outputStream.PROPERTY("FromValues") << range.getFromValues() << std::endl;
      outputStream << outputStream.PROPERTY("TillValues") << range.getTillValues() << std::endl;
      outputStream << outputStream.END_BRACKET << std::endl;
      return true;
   }



In a wrapper I call
Code:

   ADD_USER_SERIALIZER(GeographicRange);


Basically serialisation should write / read two vectors indicating a lower and a higher limit of a geodetic range.

The ASCII output looks like:

GeographicRange
{
FromValues -135 40.9799 -10000
TillValues -90 66.5133 10000
}

Which seems to be fine.

The XML output looks like:

< FromValues attribute="-135 40.9799 -10000&nl;" >
< TillValues attribute="-90 66.5133 10000&nl;&nl;" >
< /TillValues >
< /FromValues >

Which is not really the same. Besides the fact that "GeographicRange" is gone completely.

How do I make the output of both versions the same?

Cheers,
Hartwig
Back to top
View user's profile Send private message Visit poster's website
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 475
Location: France

PostPosted: Fri Dec 29, 2017 8:18 am    Post subject:
Re: Serialization differences between ASCII and XML
Reply with quote

Sorry for the false hope
removing newline ine osgDB::XMLNode::writeProperty would
forbid string property with newline...
How silly i am!!


mp3butcher wrote:
Hi Hartwig
I have no experience with osgx format
But the bug seams to come from osgDB/XMLParser.cpp
perhaps removing newline (with trimEnclosingSpaces) from strings in osgDB::XMLNode::writeString
could to the trick...
or better add newline in _characterToControlMap

You should make a pull request for this bug fix

Cheers

hartwigw wrote:
Hi,

wrote a simple serialiser for the output of a range:

Code:

namespace
{
   bool checkGeographicRange(osgPlanetCore::GeodeticData const&)
   {
      return true;
   }

   bool readGeographicRange(osgDB::InputStream& inputStream, osgPlanetCore::GeodeticData& geodeticData)
   {
      osgPlanetCore::GeographicRange geographicRange;


      if (osgPlanetWrappers::readRange(inputStream,geographicRange))
      {
         geodeticData.setGeographicRange(geographicRange);
         return true;
      } /* if */
      else
         return false;
   }
   
   bool writeGeographicRange(osgDB::OutputStream& outputStream, osgPlanetCore::GeodeticData const& geodeticData)
   {
      outputStream << std::endl;
      return osgPlanetWrappers::writeRange(outputStream,geodeticData.getGeographicRange());
   }

} /* namespace */

   template < typename Values >
   bool readRange(osgDB::InputStream& inputStream, osgPlanetCore::Range< Values >& range)
   {
      inputStream >> inputStream.BEGIN_BRACKET;
      inputStream >> inputStream.PROPERTY("FromValues") >> range.getFromValues();
      inputStream >> inputStream.PROPERTY("TillValues") >> range.getTillValues();
      inputStream >> inputStream.END_BRACKET;
      return true;
   }
   
   template < typename Values >
   bool writeRange(osgDB::OutputStream& outputStream, osgPlanetCore::Range< Values > const& range)
   {
      outputStream << outputStream.BEGIN_BRACKET << std::endl;
      outputStream << outputStream.PROPERTY("FromValues") << range.getFromValues() << std::endl;
      outputStream << outputStream.PROPERTY("TillValues") << range.getTillValues() << std::endl;
      outputStream << outputStream.END_BRACKET << std::endl;
      return true;
   }



In a wrapper I call
Code:

   ADD_USER_SERIALIZER(GeographicRange);


Basically serialisation should write / read two vectors indicating a lower and a higher limit of a geodetic range.

The ASCII output looks like:

GeographicRange
{
FromValues -135 40.9799 -10000
TillValues -90 66.5133 10000
}

Which seems to be fine.

The XML output looks like:

< FromValues attribute="-135 40.9799 -10000&nl;" >
< TillValues attribute="-90 66.5133 10000&nl;&nl;" >
< /TillValues >
< /FromValues >

Which is not really the same. Besides the fact that "GeographicRange" is gone completely.

How do I make the output of both versions the same?

Cheers,
Hartwig
Back to top
View user's profile Send private message Visit poster's website
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12127

PostPosted: Sat Dec 30, 2017 3:27 pm    Post subject:
Serialization differences between ASCII and XML
Reply with quote

Hi Hartwig,

I'm not yet back to work so just quick reply. What you describe looks
like a bug, when I return to work I'll look into it, albeit as part of
queue of support issues that have accumulated this holiday...

What would help me is a small example that illustrates the problem so
I can reproduce it at my end. If your project is open sourced then a
link to the code that you are seeing a problem with would help as
well.

As a general comment, there are lots of helper macros for serializers
that can often avoid the need for custom user serializers, for
instance if your properties are a Vec4d you should be able to just use
the macros to read/write them. Have a look through the
OpenSceneGraph/src/osgWrappers/serialzers/osg for examples of this in
action.

Robert.

On 27 December 2017 at 17:49, Hartwig Wiesmann
<> wrote:
Quote:
Hi,

wrote a simple serialiser for the output of a range:


Code:

namespace
{
bool checkGeographicRange(osgPlanetCore::GeodeticData const&)
{
return true;
}

bool readGeographicRange(osgDB::InputStream& inputStream, osgPlanetCore::GeodeticData& geodeticData)
{
osgPlanetCore::GeographicRange geographicRange;


if (osgPlanetWrappers::readRange(inputStream,geographicRange))
{
geodeticData.setGeographicRange(geographicRange);
return true;
} /* if */
else
return false;
}

bool writeGeographicRange(osgDB::OutputStream& outputStream, osgPlanetCore::GeodeticData const& geodeticData)
{
outputStream << std::endl;
return osgPlanetWrappers::writeRange(outputStream,geodeticData.getGeographicRange());
}

} /* namespace */

template < typename Values >
bool readRange(osgDB::InputStream& inputStream, osgPlanetCore::Range< Values >& range)
{
inputStream >> inputStream.BEGIN_BRACKET;
inputStream >> inputStream.PROPERTY("FromValues") >> range.getFromValues();
inputStream >> inputStream.PROPERTY("TillValues") >> range.getTillValues();
inputStream >> inputStream.END_BRACKET;
return true;
}

template < typename Values >
bool writeRange(osgDB::OutputStream& outputStream, osgPlanetCore::Range< Values > const& range)
{
outputStream << outputStream.BEGIN_BRACKET << std::endl;
outputStream << outputStream.PROPERTY("FromValues") << range.getFromValues() << std::endl;
outputStream << outputStream.PROPERTY("TillValues") << range.getTillValues() << std::endl;
outputStream << outputStream.END_BRACKET << std::endl;
return true;
}





In a wrapper I call

Code:

ADD_USER_SERIALIZER(GeographicRange);




Basically serialisation should write / read two vectors indicating a lower and a higher limit of a geodetic range.

The ASCII output looks like:

GeographicRange
{
FromValues -135 40.9799 -10000
TillValues -90 66.5133 10000
}

Which seems to be fine.

The XML output looks like:

< FromValues attribute="-135 40.9799 -10000&nl;" >
< TillValues attribute="-90 66.5133 10000&nl;&nl;" >
< /TillValues >
< /FromValues >

Which is not really the same. Besides the fact that "GeographicRange" is gone completely.

How do I make the output of both versions the same?

Cheers,
Hartwig

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72645#72645








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts osgSim::MultiSwitch Serialization stephandavid3 General 2 Wed Jul 25, 2018 7:55 pm View latest post
No new posts osgText - alignment differences using... gwaldron General 4 Thu Feb 01, 2018 5:51 pm View latest post
No new posts Serialization with virtual base classes hartwigw General 3 Sat Dec 23, 2017 11:04 am View latest post
No new posts Serialization and multiple inheritance hartwigw General 0 Mon Dec 18, 2017 8:07 pm View latest post
No new posts About BufferData'sBufferObject serial... mp3butcher Submission 1 Sat Sep 09, 2017 3:20 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP