Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for the package attribute on the types element. #904

Merged
merged 14 commits into from
Sep 27, 2022

Conversation

ratcashdev
Copy link
Contributor

@ratcashdev ratcashdev commented Jul 5, 2022

Implementation of #507 for Java.

The main idea is that we store the package attribute read from the XML to the IR, into token[0]. Then it's up to the generator to make use of that extra piece of information (controllable through sbe.type.package.override argument, defaulting to false ).

The serialization of the IR is not touched, therefore the package information is not present in the serialized IR.

Some classes in this PR, like the MultiPackageOutputManager and StringWriterOutputManager actually belong to agrona, but have been implemented here to have a testable code.
Before merging, those files/classes should be moved and substituted with a new release of agrona.

@ratcashdev ratcashdev marked this pull request as ready for review July 18, 2022 23:01
@ratcashdev
Copy link
Contributor Author

@mjpt777 @tmontgomery Hi, subject to Your time permitting, I'd appreciate a 1st, rough review of this. Thanks.

@mjpt777
Copy link
Contributor

mjpt777 commented Jul 27, 2022

Sorry but we have been busy. We need to give priority to our commercial support customers.

@ratcashdev
Copy link
Contributor Author

Sure, take your time. Just wanted to make sure this blipped on your radar.

@@ -52,7 +52,8 @@ public CodeGenerator newInstance(final Ir ir, final String outputDir)
"true".equals(System.getProperty(JAVA_GROUP_ORDER_ANNOTATION)),
"true".equals(System.getProperty(JAVA_GENERATE_INTERFACES)),
"true".equals(System.getProperty(DECODE_UNKNOWN_ENUM_VALUES)),
new PackageOutputManager(outputDir, ir.applicableNamespace()));
"true".equals(System.getProperty(TYPE_PACKAGE_OVERRIDE)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this default to true?

Copy link
Contributor Author

@ratcashdev ratcashdev Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless TYPE_PACKAGE_OVERRIDE is explicitly set to true, the generator will not respect package overrides, therefore behave like before this change - unless I am missing something here?

{

private final String baseDirName;
private final PackageOutputManager global;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming should be more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming's difficult. But tried to do my best.

@@ -105,6 +107,7 @@
public Token(
final Signal signal,
final String name,
final String packageName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should come at end of string args as new.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -361,6 +375,7 @@ public String toString()
{
private Signal signal;
private String name;
private String packageName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the default for packageName?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the default to null. Also added explanation to the javadoc.

@ratcashdev
Copy link
Contributor Author

Created real-logic/agrona#266 for the required changes in agrona.

…putManager). Should be replaced with a new version of Agrona.
@vyazelenko
Copy link
Contributor

@ratcashdev Agrona 1.17.0 was released and it contains real-logic/agrona#266.

@ratcashdev
Copy link
Contributor Author

updated to latest master.

actingPackageOutputManager = basePackageOutputManager;
}

@Override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OverRide not used in code style.

@mjpt777 mjpt777 merged commit 742cd8a into real-logic:master Sep 27, 2022
mjpt777 added a commit that referenced this pull request Sep 27, 2022
*/
public static String getTypesPackageAttribute(final Node elementNode)
{
return getAttributeValue(elementNode.getParentNode(), "package", null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not likely to be sufficient for nested composites or ref types as the parent will be different.

Copy link
Contributor Author

@ratcashdev ratcashdev Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I need to write a test case for this. So we speak about two cases as below?

...
<messageSchema package="composite.elements"
               id="3"
               semanticVersion="5.2"
               description="Unit Test"
               byteOrder="littleEndian">
    <types package="specific.package.name">
        <composite name="messageHeader" description="Message identifiers and length of message root">
            <type name="blockLength" primitiveType="uint16"/>
            <type name="templateId" primitiveType="uint16"/>
            <type name="schemaId" primitiveType="uint16"/>
            <type name="version" primitiveType="uint16"/>
        </composite>
      ...
       <!-- case number 1 -->
       <enum name="booleanEnum" encodingType="uint8" semanticType="Boolean">
            <validValue name="F">0</validValue>
            <validValue name="T">1</validValue>
        </enum>
        <composite name="futuresPrice">
            <type name="mantissa" primitiveType="int64" />
            <type name="exponent" primitiveType="int8" />
            <ref name="isSettlement" type="booleanEnum" offset="10" />
        </composite>
 
      <!-- case number 2 -->
      <composite name="outer">
            <enum name="enumOne" description="enum as uint8" encodingType="uint8" semanticType="int">
                <validValue name="Value1">1</validValue>
                <validValue name="Value10">10</validValue>
            </enum>
            <type name="zeroth" primitiveType="uint8"/>
            <set name="setOne" description="set as uint32" encodingType="uint32" semanticType="int">
                <choice name="Bit0">0</choice>
                <choice name="Bit16">16</choice>
                <choice name="Bit26">26</choice>
            </set>
            <composite name="inner">
                <type name="first" primitiveType="int64"/>
                <type name="second" primitiveType="int64"/>
            </composite>
        </composite>
    </types>
...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes these cases and consider the likes of: https://github.com/real-logic/simple-binary-encoding/blob/master/sbe-samples/src/main/resources/example-schema.xml#L32-L34

BTW I've pushed a change to better find the ancestor <types> element.

mjpt777 added a commit that referenced this pull request Sep 28, 2022
@ratcashdev
Copy link
Contributor Author

Ok, will enhance the tests as a separate PR. Thanks for the fix.

@ratcashdev
Copy link
Contributor Author

ratcashdev commented Sep 28, 2022

just realized, the case below also needs to be taken care of or at least tested (REF pointing to a type in a different package):

 <types package="specific.package.name.A">
       <enum name="booleanEnum" encodingType="uint8" semanticType="Boolean">
            <validValue name="F">0</validValue>
            <validValue name="T">1</validValue>
        </enum>
</types>

 <types package="specific.package.name.B">
       <composite name="futuresPrice">
            <type name="mantissa" primitiveType="int64" />
            <type name="exponent" primitiveType="int8" />
            <ref name="isSettlement" type="booleanEnum" offset="10" />
        </composite>
</types>

@mjpt777
Copy link
Contributor

mjpt777 commented Sep 29, 2022

Yes the <ref> case needs to be considered.

@mjpt777
Copy link
Contributor

mjpt777 commented Oct 3, 2022

When do you think you can address this?

@ratcashdev
Copy link
Contributor Author

Apologies, got sick for the past week, still on meds. Fingers cross - this week.

@ratcashdev
Copy link
Contributor Author

please have a look on #915

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants