[osg-users] Serialization differences between ASCII and XML

Hartwig Wiesmann hartwig.wiesmann at skywind.eu
Wed Dec 27 09:49:46 PST 2017


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







More information about the osg-users mailing list