You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/06/27 20:15:16 UTC

[plc4x] branch develop updated (d3dfe37 -> a81e1f7)

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git.


    from d3dfe37  - Finetuned the java code generation (Removing problems with multiple arrayFields) - Finished a first version of the KNXNet/IP MSpec (Removed the Daffodil version) - Added a sandbox driver for KNXNet/IP
     new 87368ef  - Finetuned the field names to cause less problems with Jackson for serializing and parsing - Converted ConnectionRequestInformation and ConnectionResponseDataBlock into discriminated types
     new ffb28ae  - Added Jackson annotations to enable serializing and parsing with Jackson.
     new f4ce326  - Updated Jackson to the latest version.
     new a81e1f7  - Added a test to test the generated code for serializing and parsing - Added tests for serializing and parsing parsed instances of the generated model to JSON and XML with Jackson

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../resources/templates/java/pojo-template.ftlh    |  7 ++-
 pom.xml                                            |  7 ++-
 .../resources/protocols/knxnetip/knxnetip.mspec    | 56 +++++++++++++---------
 sandbox/test-java-knxnetip-driver/pom.xml          | 14 ++++++
 .../org/apache/plc4x/java/knxnetip/IOTest.java}    | 46 ++++++++++++++----
 .../src/test/java/BenchmarkGeneratedS7.java        |  1 -
 6 files changed, 97 insertions(+), 34 deletions(-)
 copy sandbox/{test-java-s7-driver/src/test/java/BenchmarkGeneratedS7.java => test-java-knxnetip-driver/src/test/java/org/apache/plc4x/java/knxnetip/IOTest.java} (58%)


[plc4x] 03/04: - Updated Jackson to the latest version.

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit f4ce326bde5ae48cdd9b193186610a297427fffa
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Jun 27 22:12:07 2019 +0200

    - Updated Jackson to the latest version.
---
 pom.xml | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 4d2d70f..2fa24cb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -131,7 +131,7 @@
     <gson.version>2.8.0</gson.version>
     <guava.version>27.0.1-jre</guava.version>
     <hamcrest.version>1.3</hamcrest.version>
-    <jackson.version>2.9.8</jackson.version>
+    <jackson.version>2.9.9</jackson.version>
     <jmh.version>1.21</jmh.version>
     <jna.version>4.5.1</jna.version>
     <joda-time.version>2.10</joda-time.version>
@@ -230,6 +230,11 @@
       </dependency>
       <dependency>
         <groupId>com.fasterxml.jackson.dataformat</groupId>
+        <artifactId>jackson-dataformat-xml</artifactId>
+        <version>${jackson.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>com.fasterxml.jackson.dataformat</groupId>
         <artifactId>jackson-dataformat-yaml</artifactId>
         <version>${jackson.version}</version>
       </dependency>


[plc4x] 04/04: - Added a test to test the generated code for serializing and parsing - Added tests for serializing and parsing parsed instances of the generated model to JSON and XML with Jackson

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit a81e1f7c65074f8ace8866c4877cce9298354b02
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Jun 27 22:15:09 2019 +0200

    - Added a test to test the generated code for serializing and parsing
    - Added tests for serializing and parsing parsed instances of the generated model to JSON and XML with Jackson
---
 sandbox/test-java-knxnetip-driver/pom.xml          | 14 +++++++
 .../org/apache/plc4x/java/knxnetip/IOTest.java}    | 46 +++++++++++++++++-----
 .../src/test/java/BenchmarkGeneratedS7.java        |  1 -
 3 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/sandbox/test-java-knxnetip-driver/pom.xml b/sandbox/test-java-knxnetip-driver/pom.xml
index 8d9e15e..bc23e19 100644
--- a/sandbox/test-java-knxnetip-driver/pom.xml
+++ b/sandbox/test-java-knxnetip-driver/pom.xml
@@ -60,12 +60,26 @@
       <artifactId>plc4j-utils-driver-base-java</artifactId>
       <version>0.5.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-annotations</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>commons-codec</groupId>
       <artifactId>commons-codec</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.dataformat</groupId>
+      <artifactId>jackson-dataformat-xml</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-api</artifactId>
+      <scope>test</scope>
+    </dependency>
 
     <dependency>
       <groupId>org.apache.plc4x</groupId>
diff --git a/sandbox/test-java-s7-driver/src/test/java/BenchmarkGeneratedS7.java b/sandbox/test-java-knxnetip-driver/src/test/java/org/apache/plc4x/java/knxnetip/IOTest.java
similarity index 58%
copy from sandbox/test-java-s7-driver/src/test/java/BenchmarkGeneratedS7.java
copy to sandbox/test-java-knxnetip-driver/src/test/java/org/apache/plc4x/java/knxnetip/IOTest.java
index f1d95ff..5653814 100644
--- a/sandbox/test-java-s7-driver/src/test/java/BenchmarkGeneratedS7.java
+++ b/sandbox/test-java-knxnetip-driver/src/test/java/org/apache/plc4x/java/knxnetip/IOTest.java
@@ -17,27 +17,55 @@
  under the License.
  */
 
+package org.apache.plc4x.java.knxnetip;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
 import org.apache.commons.codec.binary.Hex;
-import org.apache.plc4x.java.s7.TPKTPacket;
-import org.apache.plc4x.java.s7.io.TPKTPacketIO;
+import org.apache.plc4x.java.knxnetip.io.KNXNetIPMessageIO;
 import org.apache.plc4x.java.utils.ReadBuffer;
 import org.apache.plc4x.java.utils.WriteBuffer;
+import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
 
-public class BenchmarkGeneratedS7 {
+public class IOTest {
+
+    @Test
+    public void testXml() throws Exception {
+        byte[] rData = Hex.decodeHex("0610020500180801c0a82a46c4090801c0a82a46c40a0203");
+        ObjectMapper mapper = new XmlMapper().enableDefaultTyping();
+        ReadBuffer rBuf = new ReadBuffer(rData);
+        KNXNetIPMessage packet = KNXNetIPMessageIO.parse(rBuf);
+        String xml = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(packet);
+        System.out.println(xml);
+        KNXNetIPMessage pack2 = mapper.readValue(xml, KNXNetIPMessage.class);
+        System.out.println(pack2);
+    }
+
+    @Test
+    public void testJson() throws Exception {
+        byte[] rData = Hex.decodeHex("0610020500180801c0a82a46c4090801c0a82a46c40a0203");
+        ObjectMapper mapper = new ObjectMapper().enableDefaultTyping();
+        ReadBuffer rBuf = new ReadBuffer(rData);
+        KNXNetIPMessage packet = KNXNetIPMessageIO.parse(rBuf);
+        String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(packet);
+        System.out.println(json);
+        KNXNetIPMessage pack2 = mapper.readValue(json, KNXNetIPMessage.class);
+        System.out.println(pack2);
+    }
 
-    public static void main(String[] args) throws Exception {
-                                    //        00
-        byte[] rData = Hex.decodeHex("0300006702f080320100000001005600000407120a10060001032b84000160120a10020001032b840001a0120a10010001032b840001a9120a10050001032b84000150120a10020001032b84000198120a10040001032b84000140120a10020001032b84000190");
+    @Test
+    public void testParser() throws Exception {
+        byte[] rData = Hex.decodeHex("0610020500180801c0a82a46c4090801c0a82a46c40a0203");
         long start = System.currentTimeMillis();
         int numRunsParse = 2000000;
 
         // Benchmark the parsing code
-        TPKTPacket packet = null;
+        KNXNetIPMessage packet = null;
         for(int i = 0; i < numRunsParse; i++) {
             ReadBuffer rBuf = new ReadBuffer(rData);
-            packet = TPKTPacketIO.parse(rBuf);
+            packet = KNXNetIPMessageIO.parse(rBuf);
         }
         long endParsing = System.currentTimeMillis();
 
@@ -49,7 +77,7 @@ public class BenchmarkGeneratedS7 {
         byte[] oData = null;
         for(int i = 0; i < numRunsSerialize; i++) {
             WriteBuffer wBuf = new WriteBuffer(packet.getLengthInBytes());
-            TPKTPacketIO.serialize(wBuf, packet);
+            KNXNetIPMessageIO.serialize(wBuf, packet);
             oData = wBuf.getData();
         }
         long endSerializing = System.currentTimeMillis();
diff --git a/sandbox/test-java-s7-driver/src/test/java/BenchmarkGeneratedS7.java b/sandbox/test-java-s7-driver/src/test/java/BenchmarkGeneratedS7.java
index f1d95ff..24fd194 100644
--- a/sandbox/test-java-s7-driver/src/test/java/BenchmarkGeneratedS7.java
+++ b/sandbox/test-java-s7-driver/src/test/java/BenchmarkGeneratedS7.java
@@ -28,7 +28,6 @@ import java.util.Arrays;
 public class BenchmarkGeneratedS7 {
 
     public static void main(String[] args) throws Exception {
-                                    //        00
         byte[] rData = Hex.decodeHex("0300006702f080320100000001005600000407120a10060001032b84000160120a10020001032b840001a0120a10010001032b840001a9120a10050001032b84000150120a10020001032b84000198120a10040001032b84000140120a10020001032b84000190");
         long start = System.currentTimeMillis();
         int numRunsParse = 2000000;


[plc4x] 02/04: - Added Jackson annotations to enable serializing and parsing with Jackson.

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit ffb28aec2bd84ea2b817dc887badbf4b7b71b13d
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Jun 27 22:11:04 2019 +0200

    - Added Jackson annotations to enable serializing and parsing with Jackson.
---
 .../src/main/resources/templates/java/pojo-template.ftlh           | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
index 75279ff..33abe95 100644
--- a/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
@@ -38,8 +38,10 @@ ${packageName?replace(".", "/")}/${typeName}.java
 
 package ${packageName};
 
+import com.fasterxml.jackson.annotation.*;
 import org.apache.plc4x.java.utils.SizeAware;
 
+<#if type.abstract>@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "className")</#if>
 public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??> extends ${type.parentType.name}</#if> implements SizeAware {
 
 <#if helper.isDiscriminatedType(type)>
@@ -66,7 +68,8 @@ public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??
 </#list>
 </#if>
 
-    public ${typeName}(<#list type.getAllPropertyFields() as field>${helper.getLanguageTypeNameForField(field)}<#if field.lengthType??>[]</#if> ${field.name}<#sep>, </#sep></#list>) {
+    @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
+    public ${typeName}(<#list type.getAllPropertyFields() as field>@JsonProperty("${field.name}") ${helper.getLanguageTypeNameForField(field)}<#if field.lengthType??>[]</#if> ${field.name}<#sep>, </#sep></#list>) {
 <#if type.getParentPropertyFields()?has_content>
         super(<#list type.getParentPropertyFields() as field>${field.name}<#sep>, </#sep></#list>);
 </#if>
@@ -80,6 +83,7 @@ public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??
 </#if>
 <#if helper.isDiscriminatedType(type)>
 
+    @JsonIgnore
     public Object[] getDiscriminatorValues() {
         return DISCRIMINATOR_VALUES;
     }
@@ -92,6 +96,7 @@ public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??
 
 </#list>
     @Override
+    @JsonIgnore
     public int getLengthInBytes() {
         int lengthInBits = <#if type.parentType??>super.getLengthInBytes() * 8<#else>0</#if>;
 <#list type.fields as field>


[plc4x] 01/04: - Finetuned the field names to cause less problems with Jackson for serializing and parsing - Converted ConnectionRequestInformation and ConnectionResponseDataBlock into discriminated types

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 87368ef07ec4b8a1b0fcc98eeeb02861f84a7d99
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Jun 27 22:10:01 2019 +0200

    - Finetuned the field names to cause less problems with Jackson for serializing and parsing
    - Converted ConnectionRequestInformation and ConnectionResponseDataBlock into discriminated types
---
 .../resources/protocols/knxnetip/knxnetip.mspec    | 56 +++++++++++++---------
 1 file changed, 34 insertions(+), 22 deletions(-)

diff --git a/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec b/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
index adb5a4d..5e3439e 100644
--- a/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
+++ b/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
@@ -19,40 +19,40 @@
 
 [discriminatedType 'KNXNetIPMessage'
     [implicit      uint 8  'headerLength' 'lengthInBytes']
-    [const         uint 8  'protocolVersion' '0x0A']
+    [const         uint 8  'protocolVersion' '0x10']
     [discriminator uint 16 'msgType']
     [implicit      uint 16 'totalLength' 'lengthInBytes']
     [typeSwitch 'msgType'
         ['0x0201' SearchRequest
-            [field HPAIDiscoveryEndpoint 'hPAIDiscoveryEndpoint']
+            [field HPAIDiscoveryEndpoint 'hpaiIDiscoveryEndpoint']
         ]
         ['0x0202' SearchResponse
-            [field HPAIControlEndpoint 'hPAIControlEndpoint']
-            [field DIBDeviceInfo       'dIBDeviceInfo']
-            [field DIBSuppSvcFamilies  'dIBSuppSvcFamilies']
+            [field HPAIControlEndpoint 'hpaiControlEndpoint']
+            [field DIBDeviceInfo       'dibDeviceInfo']
+            [field DIBSuppSvcFamilies  'dibSuppSvcFamilies']
         ]
         ['0x0203' DescriptionRequest
-            [field HPAIControlEndpoint 'hPAIControlEndpoint']
+            [field HPAIControlEndpoint 'hpaiControlEndpoint']
         ]
         ['0x0204' DescriptionResponse
-            [field DIBDeviceInfo       'dIBDeviceInfo']
-            [field DIBSuppSvcFamilies  'dIBSuppSvcFamilies']
+            [field DIBDeviceInfo       'dibDeviceInfo']
+            [field DIBSuppSvcFamilies  'dibSuppSvcFamilies']
         ]
         ['0x0205' ConnectionRequest
-            [field HPAIDiscoveryEndpoint        'hPAIDiscoveryEndpoint']
-            [field HPAIDataEndpoint             'hPAIDataEndpoint']
+            [field HPAIDiscoveryEndpoint        'hpaiDiscoveryEndpoint']
+            [field HPAIDataEndpoint             'hpaiDataEndpoint']
             [field ConnectionRequestInformation 'connectionRequestInformation']
         ]
         ['0x0206' ConnectionResponse
             [field uint 8 'communicationChannelId']
             [field uint 8 'status']
-            [field HPAIDataEndpoint            'hPAIDataEndpoint']
+            [field HPAIDataEndpoint            'hpaiDataEndpoint']
             [field ConnectionResponseDataBlock 'connectionResponseDataBlock']
         ]
         ['0x0207' ConnectionStateRequest
             [field    uint 8 'communicationChannelId']
             [reserved uint 8 '0x00']
-            [field HPAIControlEndpoint 'hPAIControlEndpoint']
+            [field HPAIControlEndpoint 'hpaiControlEndpoint']
         ]
         ['0x0208' ConnectionStateResponse
             [field uint 8 'communicationChannelId']
@@ -61,7 +61,7 @@
         ['0x0209' DisconnectRequest
             [field    uint 8 'communicationChannelId']
             [reserved uint 8 '0x00']
-            [field HPAIControlEndpoint 'hPAIControlEndpoint']
+            [field HPAIControlEndpoint 'hpaiControlEndpoint']
         ]
         ['0x020A' DisconnectResponse
             [field uint 8 'communicationChannelId']
@@ -136,17 +136,29 @@
     [field    uint 16   'ipPort']
 ]
 
-[type 'ConnectionRequestInformation'
-    [implicit uint 8    'structureLength' 'lengthInBytes']
-    [field    uint 8    'connectionType']
-    [field    uint 8    'knxLayer']
-    [reserved uint 8    '0x00']
+[discriminatedType 'ConnectionRequestInformation'
+    [implicit      uint 8    'structureLength' 'lengthInBytes']
+    [discriminator uint 8    'connectionType']
+    [typeSwitch 'connectionType'
+        ['0x03' ConnectionRequestInformationDeviceManagement
+        ]
+        ['0x04' ConnectionRequestInformationTunnelConnection
+            [field    uint 8    'knxLayer']
+            [reserved uint 8    '0x00']
+        ]
+    ]
 ]
 
-[type 'ConnectionResponseDataBlock'
-    [implicit uint 8     'structureLength' 'lengthInBytes']
-    [field    uint 8     'connectionType']
-    [field    KNXAddress 'knxAddress']
+[discriminatedType 'ConnectionResponseDataBlock'
+    [implicit      uint 8     'structureLength' 'lengthInBytes']
+    [discriminator uint 8     'connectionType']
+    [typeSwitch 'connectionType'
+        ['0x03' ConnectionResponseDataBlockDeviceManagement
+        ]
+        ['0x04' ConnectionResponseDataBlockTunnelConnection
+            [field         KNXAddress 'knxAddress']
+        ]
+    ]
 ]
 
 [type 'IPAddress'