Skip to content

Commit a100914

Browse files
authored
Merge branch 'develop' into feat/hop
2 parents cbc761d + 3b695e5 commit a100914

File tree

426 files changed

+40007
-8997
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

426 files changed

+40007
-8997
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ We are planning on shipping libraries for usage in:
5858
2. Go
5959
3. C (not ready for usage)
6060
4. Python (not ready for usage)
61-
5. C# (.Net) (not ready for usage)
61+
5. C# (.Net) (not ready for usage - abandoned)
6262

6363
PLC4X also integrates with other Apache projects, such as:
6464

@@ -191,7 +191,7 @@ In order to be able to build the Python module, you currently need to activate t
191191
In order to build everything the following command should work:
192192

193193
```
194-
./mvnw -P with-c,with-dotnet,with-go,with-python,with-sandbox install
194+
./mvnw -P with-c,with-go,with-python,with-sandbox install
195195
```
196196

197197
## Community

code-generation/language-c/src/test/resources/integration-test/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@
241241
<Export-Service>org.apache.plc4x.java.api.PlcDriver,org.apache.plc4x.protocol.test
242242
</Export-Service>
243243
<Import-Package>
244-
com.fasterxml.jackson.annotation;resolution:=optional,
245244
*
246245
</Import-Package>
247246
</instructions>

code-generation/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
import org.apache.commons.lang3.math.NumberUtils;
2323
import org.apache.commons.text.CaseUtils;
2424
import org.apache.plc4x.plugins.codegenerator.language.mspec.model.definitions.DefaultArgument;
25-
import org.apache.plc4x.plugins.codegenerator.language.mspec.model.references.DefaultBooleanTypeReference;
26-
import org.apache.plc4x.plugins.codegenerator.language.mspec.model.references.DefaultFloatTypeReference;
27-
import org.apache.plc4x.plugins.codegenerator.language.mspec.model.references.DefaultIntegerTypeReference;
28-
import org.apache.plc4x.plugins.codegenerator.language.mspec.model.references.DefaultVstringTypeReference;
25+
import org.apache.plc4x.plugins.codegenerator.language.mspec.model.references.*;
2926
import org.apache.plc4x.plugins.codegenerator.language.mspec.model.terms.DefaultStringLiteral;
3027
import org.apache.plc4x.plugins.codegenerator.protocol.freemarker.BaseFreemarkerLanguageTemplateHelper;
3128
import org.apache.plc4x.plugins.codegenerator.protocol.freemarker.FreemarkerException;
@@ -123,6 +120,9 @@ public String getLanguageTypeNameForTypeReference(TypeReference typeReference, S
123120
if (typeReference.isNonSimpleTypeReference()) {
124121
return typeReference.asNonSimpleTypeReference().orElseThrow().getName();
125122
}
123+
if (typeReference instanceof ByteOrderTypeReference) {
124+
return "binary.byteOrder";
125+
}
126126
SimpleTypeReference simpleTypeReference = typeReference.asSimpleTypeReference().orElseThrow();
127127
switch (simpleTypeReference.getBaseType()) {
128128
case BIT:
@@ -583,6 +583,8 @@ String getCastExpressionForTypeReference(TypeReference typeReference) {
583583
Tracer tracer = Tracer.start("castExpression");
584584
if (typeReference instanceof SimpleTypeReference) {
585585
return tracer.dive("simpleTypeRef") + getLanguageTypeNameForTypeReference(typeReference);
586+
} else if (typeReference instanceof ByteOrderTypeReference) {
587+
return tracer.dive( "byteOrderTypeRef") + "binary.ByteOrder";
586588
} else if (typeReference != null) {
587589
return tracer.dive("anyTypeRef") + "Cast" + getLanguageTypeNameForTypeReference(typeReference);
588590
} else {
@@ -618,10 +620,16 @@ private String toTernaryTermExpression(Field field, TypeReference fieldType, Ter
618620
String inlineIf = "utils.InlineIf(" + toExpression(field, new DefaultBooleanTypeReference(), a, parserArguments, serializerArguments, serialize, false) + ", " +
619621
"func() interface{} {return " + castExpressionForTypeReference + "(" + toExpression(field, fieldType, b, parserArguments, serializerArguments, serialize, false) + ")}, " +
620622
"func() interface{} {return " + castExpressionForTypeReference + "(" + toExpression(field, fieldType, c, parserArguments, serializerArguments, serialize, false) + ")})";
621-
if (fieldType.isNonSimpleTypeReference()) {
622-
return tracer.dive("nonsimpletypereference") + castExpressionForTypeReference + "(" + inlineIf + ")";
623+
if (fieldType != null) {
624+
if (fieldType instanceof ByteOrderTypeReference) {
625+
return tracer.dive("byteordertypereference") + "(" + inlineIf + ").(binary.ByteOrder)";
626+
}
627+
if (fieldType.isNonSimpleTypeReference()) {
628+
return tracer.dive("nonsimpletypereference") + castExpressionForTypeReference + "(" + inlineIf + ")";
629+
}
630+
return tracer + inlineIf + ".(" + castExpressionForTypeReference + ")";
623631
}
624-
return tracer + inlineIf + ".(" + castExpressionForTypeReference + ")";
632+
return tracer + inlineIf;
625633
} else {
626634
throw new RuntimeException("Unsupported ternary operation type " + ternaryTerm.getOperation());
627635
}
@@ -725,6 +733,10 @@ private String toLiteralTermExpression(Field field, TypeReference fieldType, Ter
725733
VariableLiteral variableLiteral = (VariableLiteral) term;
726734
if ("curPos".equals(((VariableLiteral) term).getName())) {
727735
return "(positionAware.GetPos() - startPos)";
736+
} else if ("BIG_ENDIAN".equals(((VariableLiteral) term).getName()) && (fieldType instanceof ByteOrderTypeReference)) {
737+
return "binary.BigEndian";
738+
} else if ("LITTLE_ENDIAN".equals(((VariableLiteral) term).getName()) && (fieldType instanceof ByteOrderTypeReference)) {
739+
return "binary.LittleEndian";
728740
}
729741
return tracer + toVariableExpression(field, fieldType, (VariableLiteral) term, parserArguments, serializerArguments, serialize, suppressPointerAccess);
730742
} else {
@@ -891,15 +903,15 @@ else if ((variableLiteral.getChild().isPresent()) && ((ComplexTypeDefinition) th
891903
variableLiteral.getChild()
892904
.map(child -> "." + capitalize(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, false, suppressPointerAccess, true)))
893905
.orElse("");
894-
}/*
906+
}
895907
if ((parserArguments != null) && parserArguments.stream()
896908
.anyMatch(argument -> argument.getName().equals(variableLiteralName))) {
897909
tracer = tracer.dive("parser argument");
898-
return tracer + "m." + capitalize(variableLiteralName) +
910+
return tracer + variableLiteralName +
899911
variableLiteral.getChild()
900912
.map(child -> "." + capitalize(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, false, suppressPointerAccess, true)))
901913
.orElse("");
902-
}*/
914+
}
903915
String indexCall = "";
904916
if (variableLiteral.getIndex().isPresent()) {
905917
tracer = tracer.dive("indexCall");
@@ -1582,16 +1594,21 @@ public String capitalize(String str) {
15821594
}
15831595

15841596
public String getEndiannessOptions(boolean read, boolean separatorPrefix) {
1597+
return getEndiannessOptions(read, separatorPrefix, Collections.emptyList());
1598+
}
1599+
1600+
public String getEndiannessOptions(boolean read, boolean separatorPrefix, List<Argument> parserArguments) {
15851601
Optional<Term> byteOrder = thisType.getAttribute("byteOrder");
15861602
if (byteOrder.isPresent()) {
15871603
emitRequiredImport("encoding/binary");
1588-
1589-
String functionName = read ? "WithByteOrderForReadBufferByteBased" : "WithByteOrderForByteBasedBuffer";
1590-
String byteOrderValue = ((VariableLiteral) byteOrder.get()).getName();
1591-
if("BIG_ENDIAN".equals(byteOrderValue)) {
1592-
return (separatorPrefix ? ", " : "") + "utils." + functionName + "(binary.BigEndian)";
1593-
} else if ("LITTLE_ENDIAN".equals(byteOrderValue)) {
1594-
return (separatorPrefix ? ", " : "") + "utils." + functionName + "(binary.LittleEndian)";
1604+
if(read) {
1605+
return (separatorPrefix ? ", " : "") + "utils.WithByteOrderForReadBufferByteBased(" +
1606+
toParseExpression(null, new DefaultByteOrderTypeReference(), byteOrder.orElseThrow(), parserArguments) +
1607+
")";
1608+
} else {
1609+
return (separatorPrefix ? ", " : "") + "utils.WithByteOrderForByteBasedBuffer(" +
1610+
toSerializationExpression(null, new DefaultByteOrderTypeReference(), byteOrder.orElseThrow(), parserArguments) +
1611+
")";
15951612
}
15961613
}
15971614
return "";

code-generation/language-go/src/main/resources/templates/go/complex-type-template.go.ftlh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ type _${type.name} struct {
151151
}
152152

153153
<#if type.isDiscriminatedParentTypeDefinition()>
154-
<#assign discriminatedParentType = type.asComplexTypeDefinition().orElseThrow()>
154+
<#assign complexTypeDefinition = type.asComplexTypeDefinition().orElseThrow()>
155155
type _${type.name}ChildRequirements interface {
156156
utils.Serializable
157157
GetLengthInBits(ctx context.Context) uint16
158-
<#list discriminatedParentType.getDiscriminatorNames() as discriminatorName>
158+
<#list complexTypeDefinition.getDiscriminatorNames() as discriminatorName>
159159
<#-- If the discriminator name matches that of another field, suppress the methods generation -->
160-
<#if !type.isNonDiscriminatorField(discriminatorName)>
160+
<#if type.isDiscriminatorField(discriminatorName)>
161161
<#assign typeRef=helper.getDiscriminatorTypes()[discriminatorName]>
162162
Get${discriminatorName?cap_first}() <#if typeRef.isNonSimpleTypeReference() && !typeRef.isEnumTypeReference()>I</#if>${helper.getLanguageTypeNameForTypeReference(typeRef)}
163163
</#if>
@@ -750,7 +750,7 @@ func (m *_${type.name}) GetLengthInBytes(ctx context.Context) uint16 {
750750
<#assign parserArgumentList><#if hasParserArguments><#list parserArguments as parserArgument>${parserArgument.name} ${helper.getLanguageTypeNameForTypeReference(parserArgument.type)}<#sep>, </#sep></#list></#if></#assign>
751751
<#assign parserArgumentNameList><#if hasParserArguments><#list parserArguments as parserArgument>${parserArgument.name}<#sep>, </#sep></#list></#if></#assign>
752752
func ${type.name}Parse(theBytes []byte<#if hasParserArguments>, ${parserArgumentList}</#if>) (${type.name}, error) {
753-
return ${type.name}ParseWithBuffer(context.Background(), utils.NewReadBufferByteBased(theBytes${helper.getEndiannessOptions(true, true)})<#if hasParserArguments>, ${parserArgumentNameList}</#if>)
753+
return ${type.name}ParseWithBuffer(context.Background(), utils.NewReadBufferByteBased(theBytes${helper.getEndiannessOptions(true, true, parserArguments)})<#if hasParserArguments>, ${parserArgumentNameList}</#if>)
754754
}
755755

756756
func ${type.name}ParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer<#if hasParserArguments>, ${parserArgumentList}</#if>) (${type.name}, error) {
@@ -1542,7 +1542,7 @@ func (pm *_${type.name}) SerializeParent(ctx context.Context, writeBuffer utils.
15421542
_ = m
15431543
<#else>
15441544
func (m *_${type.name}) Serialize() ([]byte, error) {
1545-
wb := utils.NewWriteBufferByteBased(utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes(context.Background())))${helper.getEndiannessOptions(false, true)})
1545+
wb := utils.NewWriteBufferByteBased(utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes(context.Background())))${helper.getEndiannessOptions(false, true, parserArguments)})
15461546
if err := m.SerializeWithWriteBuffer(context.Background(), wb); err != nil {
15471547
return nil, err
15481548
}

code-generation/language-go/src/main/resources/templates/go/data-io-template.go.ftlh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import (
7070
<#-- TODO: the code below implies that parserArguments will be null if not present... not pretty -->
7171
<#if type.parserArguments.isPresent()><#assign parserArguments=type.parserArguments.orElseThrow()></#if>
7272
func ${type.name}Parse(ctx context.Context, theBytes []byte<#if parserArguments?has_content>, <#list parserArguments as parserArgument>${parserArgument.name} <#if parserArgument.type.isNonSimpleTypeReference() && !parserArgument.type.isEnumTypeReference()>I</#if>${helper.getLanguageTypeNameForTypeReference(parserArgument.type)}<#sep>, </#sep></#list></#if>) (api.PlcValue, error) {
73-
return ${type.name}ParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes${helper.getEndiannessOptions(true, true)})<#if parserArguments?has_content>, <#list parserArguments as parserArgument>${parserArgument.name}<#sep>, </#sep></#list></#if>)
73+
return ${type.name}ParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes${helper.getEndiannessOptions(true, true, parserArguments)})<#if parserArguments?has_content>, <#list parserArguments as parserArgument>${parserArgument.name}<#sep>, </#sep></#list></#if>)
7474
}
7575

7676
func ${type.name}ParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer<#if parserArguments?has_content>, <#list parserArguments as parserArgument>${parserArgument.name} <#if parserArgument.type.isNonSimpleTypeReference() && !parserArgument.type.isEnumTypeReference()>I</#if>${helper.getLanguageTypeNameForTypeReference(parserArgument.type)}<#sep>, </#sep></#list></#if>) (api.PlcValue, error) {
@@ -238,7 +238,7 @@ func ${type.name}ParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffe
238238
}
239239

240240
func ${type.name}Serialize(value api.PlcValue<#if parserArguments?has_content>, <#list parserArguments as parserArgument>${parserArgument.name} <#if parserArgument.type.isNonSimpleTypeReference() && !parserArgument.type.isEnumTypeReference()>I</#if>${helper.getLanguageTypeNameForTypeReference(parserArgument.type)}<#sep>, </#sep></#list></#if>) ([]byte, error) {
241-
wb := utils.NewWriteBufferByteBased(${helper.getEndiannessOptions(false, false)})
241+
wb := utils.NewWriteBufferByteBased(${helper.getEndiannessOptions(false, false, parserArguments)})
242242
if err := ${type.name}SerializeWithWriteBuffer(context.Background(), wb, value<#if parserArguments?has_content>, <#list parserArguments as parserArgument>${parserArgument.name}<#sep>, </#sep></#list></#if>); err != nil {
243243
return nil, err
244244
}

code-generation/language-go/src/test/resources/plc4go/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@
145145
<Export-Service>org.apache.plc4x.java.api.PlcDriver,org.apache.plc4x.protocol.test
146146
</Export-Service>
147147
<Import-Package>
148-
com.fasterxml.jackson.annotation;resolution:=optional,
149148
*
150149
</Import-Package>
151150
</instructions>

code-generation/language-java/src/test/resources/integration-test/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
<Export-Service>org.apache.plc4x.java.api.PlcDriver,org.apache.plc4x.protocol.test
9797
</Export-Service>
9898
<Import-Package>
99-
com.fasterxml.jackson.annotation;resolution:=optional,
10099
*
101100
</Import-Package>
102101
</instructions>
@@ -166,11 +165,6 @@
166165
<artifactId>commons-lang3</artifactId>
167166
</dependency>
168167

169-
<dependency>
170-
<groupId>com.fasterxml.jackson.core</groupId>
171-
<artifactId>jackson-annotations</artifactId>
172-
</dependency>
173-
174168
<dependency>
175169
<groupId>org.apache.plc4x</groupId>
176170
<artifactId>plc4j-utils-test-utils</artifactId>

code-generation/language-python/src/test/resources/integration-test/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
<Export-Service>org.apache.plc4x.java.api.PlcDriver,org.apache.plc4x.protocol.test
9797
</Export-Service>
9898
<Import-Package>
99-
com.fasterxml.jackson.annotation;resolution:=optional,
10099
*
101100
</Import-Package>
102101
</instructions>
@@ -166,11 +165,6 @@
166165
<artifactId>commons-lang3</artifactId>
167166
</dependency>
168167

169-
<dependency>
170-
<groupId>com.fasterxml.jackson.core</groupId>
171-
<artifactId>jackson-annotations</artifactId>
172-
</dependency>
173-
174168
<dependency>
175169
<groupId>org.apache.plc4x</groupId>
176170
<artifactId>plc4j-utils-test-utils</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.plc4x.plugins.codegenerator.language.mspec.model.references;
21+
22+
import org.apache.plc4x.plugins.codegenerator.types.references.ByteOrderTypeReference;
23+
24+
public class DefaultByteOrderTypeReference implements ByteOrderTypeReference {
25+
26+
}

code-generation/tests/protocol-test-java/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@
117117
<artifactId>commons-lang3</artifactId>
118118
</dependency>
119119

120-
<dependency>
121-
<groupId>com.fasterxml.jackson.core</groupId>
122-
<artifactId>jackson-annotations</artifactId>
123-
</dependency>
124-
125120
<dependency>
126121
<groupId>org.apache.plc4x</groupId>
127122
<artifactId>plc4j-utils-test-utils</artifactId>

0 commit comments

Comments
 (0)