Skip to content

Commit

Permalink
fix(opcua): fix issues with PascalString
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 3, 2023
1 parent 40644f7 commit 4610930
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions plc4go/protocols/opcua/readwrite/model/PascalString.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plc4go/protocols/opcua/readwrite/model/StaticHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ func Utf8LengthToPascalLength(_ context.Context, stringValue string) int32 {
}

func PascalLengthToUtf8Length(_ context.Context, slength int32) int32 {
return utils.Max(slength*8, 0)
return utils.Max(slength, 0)
}
2 changes: 1 addition & 1 deletion plc4go/spi/testutils/DriverTestRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func RunDriverTestsuite(t *testing.T, driver plc4go.PlcDriver, testPath string,
}
t.Logf("Running testcase %s", testcase.name)
if err := testsuite.Run(t, driverManager, testcase); err != nil {
testsuite.LogDelimiterSection(t, "=", "Failure:\n%+v", err)
testsuite.LogDelimiterSection(t, "=", "Failure:\n%s", err)
t.FailNow()
}
})
Expand Down
2 changes: 1 addition & 1 deletion plc4go/tests/drivers/tests/opcua_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
func TestOPCUADriver(t *testing.T) {
t.Skip("Not yet finished")
parser := func(readBufferByteBased utils.ReadBufferByteBased) (any, error) {
return readWriteModel.MessagePDUParseWithBuffer(context.Background(), readBufferByteBased, true)
return readWriteModel.MessagePDUParseWithBuffer(context.Background(), readBufferByteBased, false)
}
optionsForTesting := testutils.EnrichOptionsWithOptionsForTesting(t)
testutils.RunDriverTestsuite(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ public String getStringValue() {

public int getStringLength() {
return (int)
((org.apache.plc4x.java.opcua.readwrite.utils.StaticHelper.pascalLengthToUtf8Length(
org.apache.plc4x.java.opcua.readwrite.utils.StaticHelper.utf8LengthToPascalLength(
getStringValue())))
/ (8));
(org.apache.plc4x.java.opcua.readwrite.utils.StaticHelper.pascalLengthToUtf8Length(
org.apache.plc4x.java.opcua.readwrite.utils.StaticHelper.utf8LengthToPascalLength(
getStringValue())));
}

public void serialize(WriteBuffer writeBuffer) throws SerializationException {
Expand Down Expand Up @@ -118,9 +117,8 @@ public static PascalString staticParse(ReadBuffer readBuffer) throws ParseExcept
readVirtualField(
"stringLength",
int.class,
(org.apache.plc4x.java.opcua.readwrite.utils.StaticHelper.pascalLengthToUtf8Length(
sLength))
/ (8));
org.apache.plc4x.java.opcua.readwrite.utils.StaticHelper.pascalLengthToUtf8Length(
sLength));

String stringValue =
readSimpleField("stringValue", readString(readBuffer, (stringLength) * (8)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public static int utf8LengthToPascalLength(String stringValue) {
}

public static int pascalLengthToUtf8Length(int slength) {
return Math.max(slength * 8, 0);
return Math.max(slength, 0);
}
}
4 changes: 2 additions & 2 deletions protocols/opcua/src/main/xslt/opc-manual.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@

[type PascalString
[implicit int 32 sLength 'STATIC_CALL("utf8LengthToPascalLength", stringValue)' ]
[virtual int 32 stringLength 'STATIC_CALL("pascalLengthToUtf8Length", sLength)/8' ]
[simple vstring 'stringLength*8' stringValue ]
[virtual int 32 stringLength 'STATIC_CALL("pascalLengthToUtf8Length", sLength)' ]
[simple vstring 'stringLength*8' stringValue ]
]

[type PascalByteString
Expand Down

0 comments on commit 4610930

Please sign in to comment.