Closed SchrodingersGat closed 6 years ago
The generated map decode routines are now significantly improved. The process for decoding a primitive from the map is as follows:
This way, missing values are ignored, as are mal-formed values (e.g. "1234xx" cannot be converted to an integer)
Some example code for the improved mapDecode_ routine (generated code):
QString key; // Temporary map key variable
bool ok = false; // Temporary data validation variable
unsigned _pg_i = 0; // Array iterator
// Number of map elements
key = _pg_prename + ":size";
if(_pg_map.contains(key))
{
_pg_map[key].toUInt(&ok);
if(ok)
_pg_user->size = _pg_map[key].toUInt();
}
// Manual RPM setpoint timeout
key = _pg_prename + ":manualRpmTimeout";
if(_pg_map.contains(key))
{
_pg_map[key].toUInt(&ok);
if(ok)
_pg_user->manualRpmTimeout = _pg_map[key].toUInt();
}
Just out of pure curiosity, why are the values stored as QString rather than QVariant?
No particular reason, apart from providing consistent comparison between different variables. Enforcing QString means that there's no ambiguity (and the data types are defined in protogen anyway). Is there a specific advantage you could see from using QVariant?
Well we've been using QJsonDocument, et. al., lately, which basically gives you a big map of quasi-QVariants and it's pretty slick. So really it was more that I was wondering whether you'd seen any specific advantages to using QString
I'll have a look at the way I am using the QMap and see if I can shoehorn a QVariantMap. You'll owe me a drink :)
Instead of QMap<QString, QString> it now uses QVariantMap.
Everything else works the same. The encode routines are a bit cleaner now as they rely on the QVariant object to correctly "encode" the primitive types.
It looks like the map encode / decode functionality is incomplete. In ProtocolStructure.cpp, at the end of the function getMapEncodeString() and getMapDecodeString() the code is not yet implemented.
Also I noticed that if you set a global mapfile="somefile" you don't get any output. This is contrary to the text output functions; which, if you set a global textprint file you get outputs for every structure.
Bill, when does ProtocolStructure::GetMapEncodeString actually get called? I have put some debug messages in there that never get displayed.
As far as I can tell, all the necessary mapEncode / mapDecode functions are in:
ProtocolStructre::getMapEncodeFunctionString
ProtocolField::getMapEncodeString
If you can provide the case where ProtocolStrucutre::getMapEncodeString is actually called, I can test and fix the missing code.
Run it against the exampleprotocol.xml, that will show the problem.
On Wed, Apr 18, 2018, 6:44 PM Oliver notifications@github.com wrote:
Bill, when does ProtocolStructure::GetMapEncodeString actually get called? I have put some debug messages in there that never get displayed.
As far as I can tell, all the necessary mapEncode / mapDecode functions are in:
ProtocolStructre::getMapEncodeFunctionString
ProtocolField::getMapEncodeString
If you can provide the case where ProtocolStrucutre::getMapEncodeString is actually called, I can test and fix the missing code.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/billvaglienti/ProtoGen/pull/76#issuecomment-382582460, or mute the thread https://github.com/notifications/unsubscribe-auth/AKWWHoD3t-4XlZuYwJ9lz3HEKkOzKmYnks5tp-v6gaJpZM4TEWtX .
Thanks, I have added "mapfile" to the test protocol so this feature is tested there too.
I think I have implemented all the different encode/decode cases now...
I've also made the global "mapfile" declaration force encode/decode functions, as per your other request.
This PR adds the ability to encode (and decode) a protogen structure to a QMap<QString, QString>, essentially providing a key:value pair encoding for the structure.
(This is functionality I have been using but previously it was written in Python and an extra script ran through the same .xml file)
This functionality is similar to the textprint functions but it provides some advantages:
Example
Here is an example xml descriptor:
And the resulting code: