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 2020/03/26 12:51:46 UTC
[plc4x] branch develop updated: - Made the length-in-bits argument
optional for string types simple-types.
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
The following commit(s) were added to refs/heads/develop by this push:
new 648b8b6 - Made the length-in-bits argument optional for string types simple-types.
648b8b6 is described below
commit 648b8b6f6df0fb0b724957773a1746f133c807cd
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Mar 26 13:51:39 2020 +0100
- Made the length-in-bits argument optional for string types simple-types.
---
.../org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4 | 3 +++
.../codegenerator/language/mspec/parser/MessageFormatListener.java | 6 +++---
protocols/s7/src/main/resources/protocols/s7/s7.mspec | 4 ++--
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4 b/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
index 1e51322..d0a2943 100644
--- a/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
+++ b/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
@@ -143,7 +143,10 @@ dataType
| base='float' exponent=INTEGER_LITERAL '.' mantissa=INTEGER_LITERAL
| base='ufloat' exponent=INTEGER_LITERAL '.' mantissa=INTEGER_LITERAL
/* For the following types the parsing/serialization has to be handled manually */
+ /* Fixed length string parsing */
| base='string' size=INTEGER_LITERAL encoding=idExpression
+ /* Variable length string parsing */
+ | base='string' encoding=idExpression
| base='time'
| base='date'
| base='dateTime'
diff --git a/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java b/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
index 62c701c..1608bcb 100644
--- a/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
+++ b/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
@@ -438,9 +438,9 @@ public class MessageFormatListener extends MSpecBaseListener {
private SimpleTypeReference getSimpleTypeReference(MSpecParser.DataTypeContext ctx) {
SimpleTypeReference.SimpleBaseType simpleBaseType =
SimpleTypeReference.SimpleBaseType.valueOf(ctx.base.getText().toUpperCase());
- // String types need an additional "encoding" field.
- if ((ctx.size != null) && (ctx.encoding != null)) {
- int size = Integer.parseInt(ctx.size.getText());
+ // String types need an additional "encoding" field and an optional size.
+ if (ctx.encoding != null) {
+ int size = (ctx.size != null) ? Integer.parseInt(ctx.size.getText()) : -1;
String encoding = ctx.encoding.getText();
return new DefaultStringTypeReference(simpleBaseType, size, encoding);
}
diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
index c3edd82..f4bbbd5 100644
--- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec
+++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
@@ -338,10 +338,10 @@
['42' String
]
['43' String
- [manual string 256 'UTF-8' 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", io, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", io, _value, _type.encoding)' '_value.length + 2']
+ [manual string 'UTF-8' 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", io, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", io, _value, _type.encoding)' '_value.length + 2']
]
['44' String
- [manual string 256 'UTF-16' 'value''STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", io, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", io, _value, _type.encoding)' '(_value.length * 2) + 2']
+ [manual string 'UTF-16' 'value''STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", io, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", io, _value, _type.encoding)' '(_value.length * 2) + 2']
]
// -----------------------------------------