Utility for generating Python serializable message classes
  • XSLT 68.4%
  • Python 20.1%
  • Java 11.5%
Find a file
2023-09-23 09:58:00 +02:00
libs allow all defintions to goto in a single file. Added parameter 'allInOneFile' to the XML file set. 2023-07-28 01:25:40 +02:00
pymessage added missing generated files 2023-09-23 09:58:00 +02:00
transform fixed a few XSL generation problems 2023-09-18 09:08:23 +02:00
.gitignore initial commit 2023-07-19 18:32:58 +03:00
build.gradle initial commit 2023-07-19 18:32:58 +03:00
LICENSE Initial commit 2023-07-19 17:22:04 +03:00
README.md update README 2023-07-28 08:10:48 +02:00
settings.gradle initial commit 2023-07-19 18:32:58 +03:00
version.json initial commit 2023-07-19 18:32:58 +03:00

py-struct-generate

Utility for generating Python serializable message classes

This utility is able to generate Python serializable message classes based upon XML definitions. A simple message definition could like.

<Messages>
    <Message name="SubMessage" >
	   <Attribute name="subBool" type="bool"/>
	   <Attribute name="subString" type="str"/>
	   <Attribute name="subLong" type="long"/>
	</Message>

	<Message name="TestMessage">
		<Imports>
			<Import path="msg.generated" msgClass="SubMessage"/>
		</Imports>
		<Attribute name="intValue" type="int"/>
		<Attribute name="strValue" type="str"/>
		<Attribute name="stringArray" type="str" list="[]"/>
		<Attribute name="intArray" type="int" list="[]"/>
		<Attribute name="subMsgs" type="SubMessage" list="[]"/>
		<Attribute name="endValue" type="int"/>
	</Message>
<Messages>

The java program ./transform/src/main/java/PyTransform take one argument pointing at the XML defintions. The program will generate Python message corsponding message classes.

The simple defintions above are found in the directory ./transform/xml and can be used to generate test message classes.

To generate you may execute the PyTransform program with the following command given that your working directory is ./transform

java -jar ../libs/pymessage-1.0.jar -xml ./xml/TestMessagesFileSet.xml 

The generated is found in the directory ./pymessage/net/generated/

Generated message classes can be generated in a single module file or one file per message class. The behaviour is controlled be the definitions in the program XML definition file. E.g.

<?xml version="1.0" encoding="UTF-8"?>
<MessageFiles>
	<MessageFile  file="./xml/TestMessage.xml" outPath="../pymessage/msg/generated/" package="msg.generated" allInOneFile="True"/>
</MessageFiles>

The parameter allInOneFile defines if generated message classes should be placed in separated modules files or a single file. In case all generated message classes are placed in one file, the name of the file will be equal to the XML filename defining the message classes.

There is also trivial test program that illustrates how to use generated message classes ./pymessage/test.py

The rest is in the source.