You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2021/11/01 16:20:29 UTC
[plc4x] branch feature/mspec-ng updated: fix(plc4go/codgen): fix
optional fields not emitting contexts
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch feature/mspec-ng
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/mspec-ng by this push:
new 9b31501 fix(plc4go/codgen): fix optional fields not emitting contexts
9b31501 is described below
commit 9b31501cea018fc743af8da47cdf0cf70e4a14f9
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Nov 1 17:14:32 2021 +0100
fix(plc4go/codgen): fix optional fields not emitting contexts
---
.../resources/templates/go/model-template.go.ftlh | 18 +
.../BACnetConfirmedServiceRequestWriteProperty.go | 12 +
.../model/BACnetUnconfirmedServiceRequestWhoHas.go | 48 ++
.../plc4go/bacnetip/readwrite/model/NPDU.go | 24 +
.../knxnetip/readwrite/model/ConnectionResponse.go | 24 +
.../plc4go/s7/readwrite/model/COTPPacket.go | 12 +
.../plc4go/s7/readwrite/model/S7Message.go | 24 +
...ayloadUserDataItemCpuFunctionMsgSubscription.go | 12 +
plc4go/internal/plc4go/s7/s7Io_test.go | 728 ++++++++++-----------
9 files changed, 531 insertions(+), 371 deletions(-)
diff --git a/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh b/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh
index c5187f1..8a20c8e 100644
--- a/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh
+++ b/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh
@@ -839,12 +839,21 @@ func ${type.name}Parse(readBuffer utils.ReadBuffer<#if hasParserArguments>, ${pa
}
${optionalField.name} = &_val
<#elseif helper.isEnumField(field)>
+ if pullErr := readBuffer.PullContext("${optionalField.name}"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := ${helper.getLanguageTypeNameForField(field)}Parse(readBuffer)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing '${optionalField.name}' field")<@emitImport import="github.com/pkg/errors" />
}
${optionalField.name} = &_val
+ if closeErr := readBuffer.CloseContext("${optionalField.name}"); closeErr != nil {
+ return nil, closeErr
+ }
<#else>
+ if pullErr := readBuffer.PullContext("${optionalField.name}"); pullErr != nil {
+ return nil, pullErr
+ }
<@compress single_line=true>
<#assign complexTypeReference=optionalField.type.asComplexTypeReference().orElseThrow()>
<#assign typeName=complexTypeReference.name>
@@ -871,6 +880,9 @@ func ${type.name}Parse(readBuffer utils.ReadBuffer<#if hasParserArguments>, ${pa
return nil, errors.Wrap(_err, "Error parsing '${optionalField.name}' field")<@emitImport import="github.com/pkg/errors" />
}
${optionalField.name} = Cast${helper.getLanguageTypeNameForField(field)}(_val)
+ if closeErr := readBuffer.CloseContext("${optionalField.name}"); closeErr != nil {
+ return nil, closeErr
+ }
</#if>
}
<#break>
@@ -1307,8 +1319,14 @@ func (m *${type.name}) Serialize(writeBuffer utils.WriteBuffer<#if helper.getSer
_${optionalField.name}Err := ${helper.getWriteBufferWriteMethodCall(optionalField.name, simpleTypeReference, "*(" + optionalField.name + ")", optionalField)}
<#else>
<#assign complexTypeReference = optionalField.type>
+ if pushErr := writeBuffer.PushContext("${optionalField.name}"); pushErr != nil {
+ return pushErr
+ }
${optionalField.name} = m.${optionalField.name?cap_first}
_${optionalField.name}Err := ${optionalField.name}.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("${optionalField.name}"); popErr != nil {
+ return popErr
+ }
</#if>
if _${optionalField.name}Err != nil {
return errors.Wrap(_${optionalField.name}Err, "Error serializing '${optionalField.name}' field")<@emitImport import="github.com/pkg/errors" />
diff --git a/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetConfirmedServiceRequestWriteProperty.go b/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetConfirmedServiceRequestWriteProperty.go
index d0b4cfe..5b7eb41 100644
--- a/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetConfirmedServiceRequestWriteProperty.go
+++ b/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetConfirmedServiceRequestWriteProperty.go
@@ -240,11 +240,17 @@ func BACnetConfirmedServiceRequestWritePropertyParse(readBuffer utils.ReadBuffer
curPos = readBuffer.GetPos() - startPos
var priority *BACnetTag = nil
if bool((curPos) < ((len) - (1))) {
+ if pullErr := readBuffer.PullContext("priority"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := BACnetTagParse(readBuffer)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'priority' field")
}
priority = CastBACnetTag(_val)
+ if closeErr := readBuffer.CloseContext("priority"); closeErr != nil {
+ return nil, closeErr
+ }
}
if closeErr := readBuffer.CloseContext("BACnetConfirmedServiceRequestWriteProperty"); closeErr != nil {
@@ -347,8 +353,14 @@ func (m *BACnetConfirmedServiceRequestWriteProperty) Serialize(writeBuffer utils
// Optional Field (priority) (Can be skipped, if the value is null)
var priority *BACnetTag = nil
if m.Priority != nil {
+ if pushErr := writeBuffer.PushContext("priority"); pushErr != nil {
+ return pushErr
+ }
priority = m.Priority
_priorityErr := priority.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("priority"); popErr != nil {
+ return popErr
+ }
if _priorityErr != nil {
return errors.Wrap(_priorityErr, "Error serializing 'priority' field")
}
diff --git a/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetUnconfirmedServiceRequestWhoHas.go b/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetUnconfirmedServiceRequestWhoHas.go
index 082e67c..c133bf3 100644
--- a/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetUnconfirmedServiceRequestWhoHas.go
+++ b/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetUnconfirmedServiceRequestWhoHas.go
@@ -129,41 +129,65 @@ func BACnetUnconfirmedServiceRequestWhoHasParse(readBuffer utils.ReadBuffer, len
// Optional Field (deviceInstanceRangeLowLimit) (Can be skipped, if a given expression evaluates to false)
var deviceInstanceRangeLowLimit *BACnetComplexTagUnsignedInteger = nil
{
+ if pullErr := readBuffer.PullContext("deviceInstanceRangeLowLimit"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := BACnetComplexTagParse(readBuffer, uint8(0), BACnetDataType_UNSIGNED_INTEGER)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'deviceInstanceRangeLowLimit' field")
}
deviceInstanceRangeLowLimit = CastBACnetComplexTagUnsignedInteger(_val)
+ if closeErr := readBuffer.CloseContext("deviceInstanceRangeLowLimit"); closeErr != nil {
+ return nil, closeErr
+ }
}
// Optional Field (deviceInstanceRangeHighLimit) (Can be skipped, if a given expression evaluates to false)
var deviceInstanceRangeHighLimit *BACnetComplexTagUnsignedInteger = nil
if bool((deviceInstanceRangeLowLimit) != (nil)) {
+ if pullErr := readBuffer.PullContext("deviceInstanceRangeHighLimit"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := BACnetComplexTagParse(readBuffer, uint8(1), BACnetDataType_UNSIGNED_INTEGER)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'deviceInstanceRangeHighLimit' field")
}
deviceInstanceRangeHighLimit = CastBACnetComplexTagUnsignedInteger(_val)
+ if closeErr := readBuffer.CloseContext("deviceInstanceRangeHighLimit"); closeErr != nil {
+ return nil, closeErr
+ }
}
// Optional Field (objectIdentifier) (Can be skipped, if a given expression evaluates to false)
var objectIdentifier *BACnetComplexTagOctetString = nil
{
+ if pullErr := readBuffer.PullContext("objectIdentifier"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := BACnetComplexTagParse(readBuffer, uint8(2), BACnetDataType_OCTET_STRING)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'objectIdentifier' field")
}
objectIdentifier = CastBACnetComplexTagOctetString(_val)
+ if closeErr := readBuffer.CloseContext("objectIdentifier"); closeErr != nil {
+ return nil, closeErr
+ }
}
// Optional Field (objectName) (Can be skipped, if a given expression evaluates to false)
var objectName *BACnetComplexTagOctetString = nil
if bool((objectIdentifier) == (nil)) {
+ if pullErr := readBuffer.PullContext("objectName"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := BACnetComplexTagParse(readBuffer, uint8(3), BACnetDataType_OCTET_STRING)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'objectName' field")
}
objectName = CastBACnetComplexTagOctetString(_val)
+ if closeErr := readBuffer.CloseContext("objectName"); closeErr != nil {
+ return nil, closeErr
+ }
}
if closeErr := readBuffer.CloseContext("BACnetUnconfirmedServiceRequestWhoHas"); closeErr != nil {
@@ -191,8 +215,14 @@ func (m *BACnetUnconfirmedServiceRequestWhoHas) Serialize(writeBuffer utils.Writ
// Optional Field (deviceInstanceRangeLowLimit) (Can be skipped, if the value is null)
var deviceInstanceRangeLowLimit *BACnetComplexTagUnsignedInteger = nil
if m.DeviceInstanceRangeLowLimit != nil {
+ if pushErr := writeBuffer.PushContext("deviceInstanceRangeLowLimit"); pushErr != nil {
+ return pushErr
+ }
deviceInstanceRangeLowLimit = m.DeviceInstanceRangeLowLimit
_deviceInstanceRangeLowLimitErr := deviceInstanceRangeLowLimit.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("deviceInstanceRangeLowLimit"); popErr != nil {
+ return popErr
+ }
if _deviceInstanceRangeLowLimitErr != nil {
return errors.Wrap(_deviceInstanceRangeLowLimitErr, "Error serializing 'deviceInstanceRangeLowLimit' field")
}
@@ -201,8 +231,14 @@ func (m *BACnetUnconfirmedServiceRequestWhoHas) Serialize(writeBuffer utils.Writ
// Optional Field (deviceInstanceRangeHighLimit) (Can be skipped, if the value is null)
var deviceInstanceRangeHighLimit *BACnetComplexTagUnsignedInteger = nil
if m.DeviceInstanceRangeHighLimit != nil {
+ if pushErr := writeBuffer.PushContext("deviceInstanceRangeHighLimit"); pushErr != nil {
+ return pushErr
+ }
deviceInstanceRangeHighLimit = m.DeviceInstanceRangeHighLimit
_deviceInstanceRangeHighLimitErr := deviceInstanceRangeHighLimit.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("deviceInstanceRangeHighLimit"); popErr != nil {
+ return popErr
+ }
if _deviceInstanceRangeHighLimitErr != nil {
return errors.Wrap(_deviceInstanceRangeHighLimitErr, "Error serializing 'deviceInstanceRangeHighLimit' field")
}
@@ -211,8 +247,14 @@ func (m *BACnetUnconfirmedServiceRequestWhoHas) Serialize(writeBuffer utils.Writ
// Optional Field (objectIdentifier) (Can be skipped, if the value is null)
var objectIdentifier *BACnetComplexTagOctetString = nil
if m.ObjectIdentifier != nil {
+ if pushErr := writeBuffer.PushContext("objectIdentifier"); pushErr != nil {
+ return pushErr
+ }
objectIdentifier = m.ObjectIdentifier
_objectIdentifierErr := objectIdentifier.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("objectIdentifier"); popErr != nil {
+ return popErr
+ }
if _objectIdentifierErr != nil {
return errors.Wrap(_objectIdentifierErr, "Error serializing 'objectIdentifier' field")
}
@@ -221,8 +263,14 @@ func (m *BACnetUnconfirmedServiceRequestWhoHas) Serialize(writeBuffer utils.Writ
// Optional Field (objectName) (Can be skipped, if the value is null)
var objectName *BACnetComplexTagOctetString = nil
if m.ObjectName != nil {
+ if pushErr := writeBuffer.PushContext("objectName"); pushErr != nil {
+ return pushErr
+ }
objectName = m.ObjectName
_objectNameErr := objectName.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("objectName"); popErr != nil {
+ return popErr
+ }
if _objectNameErr != nil {
return errors.Wrap(_objectNameErr, "Error serializing 'objectName' field")
}
diff --git a/plc4go/internal/plc4go/bacnetip/readwrite/model/NPDU.go b/plc4go/internal/plc4go/bacnetip/readwrite/model/NPDU.go
index afcc7e4..226f115 100644
--- a/plc4go/internal/plc4go/bacnetip/readwrite/model/NPDU.go
+++ b/plc4go/internal/plc4go/bacnetip/readwrite/model/NPDU.go
@@ -313,21 +313,33 @@ func NPDUParse(readBuffer utils.ReadBuffer, npduLength uint16) (*NPDU, error) {
// Optional Field (nlm) (Can be skipped, if a given expression evaluates to false)
var nlm *NLM = nil
if messageTypeFieldPresent {
+ if pullErr := readBuffer.PullContext("nlm"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := NLMParse(readBuffer, uint16(npduLength)-uint16(uint16(uint16(uint16(uint16(uint16(2))+uint16(uint16(utils.InlineIf(sourceSpecified, func() interface{} { return uint16(uint16(uint16(3)) + uint16((*sourceLength))) }, func() interface{} { return uint16(uint16(0)) }).(uint16))))+uint16(uint16(utils.InlineIf(destinationSpecified, func() interface{} { return uint16(uint16(uint16(3)) + uint16((*destinationLength))) }, func() interface{} { return uint16(uint16(0)) }).(uint16))))+ [...]
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'nlm' field")
}
nlm = CastNLM(_val)
+ if closeErr := readBuffer.CloseContext("nlm"); closeErr != nil {
+ return nil, closeErr
+ }
}
// Optional Field (apdu) (Can be skipped, if a given expression evaluates to false)
var apdu *APDU = nil
if !(messageTypeFieldPresent) {
+ if pullErr := readBuffer.PullContext("apdu"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := APDUParse(readBuffer, uint16(npduLength)-uint16(uint16(uint16(uint16(uint16(uint16(2))+uint16(uint16(utils.InlineIf(sourceSpecified, func() interface{} { return uint16(uint16(uint16(3)) + uint16((*sourceLength))) }, func() interface{} { return uint16(uint16(0)) }).(uint16))))+uint16(uint16(utils.InlineIf(destinationSpecified, func() interface{} { return uint16(uint16(uint16(3)) + uint16((*destinationLength))) }, func() interface{} { return uint16(uint16(0)) }).(uint16)))) [...]
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'apdu' field")
}
apdu = CastAPDU(_val)
+ if closeErr := readBuffer.CloseContext("apdu"); closeErr != nil {
+ return nil, closeErr
+ }
}
if closeErr := readBuffer.CloseContext("NPDU"); closeErr != nil {
@@ -486,8 +498,14 @@ func (m *NPDU) Serialize(writeBuffer utils.WriteBuffer) error {
// Optional Field (nlm) (Can be skipped, if the value is null)
var nlm *NLM = nil
if m.Nlm != nil {
+ if pushErr := writeBuffer.PushContext("nlm"); pushErr != nil {
+ return pushErr
+ }
nlm = m.Nlm
_nlmErr := nlm.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("nlm"); popErr != nil {
+ return popErr
+ }
if _nlmErr != nil {
return errors.Wrap(_nlmErr, "Error serializing 'nlm' field")
}
@@ -496,8 +514,14 @@ func (m *NPDU) Serialize(writeBuffer utils.WriteBuffer) error {
// Optional Field (apdu) (Can be skipped, if the value is null)
var apdu *APDU = nil
if m.Apdu != nil {
+ if pushErr := writeBuffer.PushContext("apdu"); pushErr != nil {
+ return pushErr
+ }
apdu = m.Apdu
_apduErr := apdu.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("apdu"); popErr != nil {
+ return popErr
+ }
if _apduErr != nil {
return errors.Wrap(_apduErr, "Error serializing 'apdu' field")
}
diff --git a/plc4go/internal/plc4go/knxnetip/readwrite/model/ConnectionResponse.go b/plc4go/internal/plc4go/knxnetip/readwrite/model/ConnectionResponse.go
index d89a32d..f1269b5 100644
--- a/plc4go/internal/plc4go/knxnetip/readwrite/model/ConnectionResponse.go
+++ b/plc4go/internal/plc4go/knxnetip/readwrite/model/ConnectionResponse.go
@@ -143,21 +143,33 @@ func ConnectionResponseParse(readBuffer utils.ReadBuffer) (*KnxNetIpMessage, err
// Optional Field (hpaiDataEndpoint) (Can be skipped, if a given expression evaluates to false)
var hpaiDataEndpoint *HPAIDataEndpoint = nil
if bool((status) == (Status_NO_ERROR)) {
+ if pullErr := readBuffer.PullContext("hpaiDataEndpoint"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := HPAIDataEndpointParse(readBuffer)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'hpaiDataEndpoint' field")
}
hpaiDataEndpoint = CastHPAIDataEndpoint(_val)
+ if closeErr := readBuffer.CloseContext("hpaiDataEndpoint"); closeErr != nil {
+ return nil, closeErr
+ }
}
// Optional Field (connectionResponseDataBlock) (Can be skipped, if a given expression evaluates to false)
var connectionResponseDataBlock *ConnectionResponseDataBlock = nil
if bool((status) == (Status_NO_ERROR)) {
+ if pullErr := readBuffer.PullContext("connectionResponseDataBlock"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := ConnectionResponseDataBlockParse(readBuffer)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'connectionResponseDataBlock' field")
}
connectionResponseDataBlock = CastConnectionResponseDataBlock(_val)
+ if closeErr := readBuffer.CloseContext("connectionResponseDataBlock"); closeErr != nil {
+ return nil, closeErr
+ }
}
if closeErr := readBuffer.CloseContext("ConnectionResponse"); closeErr != nil {
@@ -204,8 +216,14 @@ func (m *ConnectionResponse) Serialize(writeBuffer utils.WriteBuffer) error {
// Optional Field (hpaiDataEndpoint) (Can be skipped, if the value is null)
var hpaiDataEndpoint *HPAIDataEndpoint = nil
if m.HpaiDataEndpoint != nil {
+ if pushErr := writeBuffer.PushContext("hpaiDataEndpoint"); pushErr != nil {
+ return pushErr
+ }
hpaiDataEndpoint = m.HpaiDataEndpoint
_hpaiDataEndpointErr := hpaiDataEndpoint.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("hpaiDataEndpoint"); popErr != nil {
+ return popErr
+ }
if _hpaiDataEndpointErr != nil {
return errors.Wrap(_hpaiDataEndpointErr, "Error serializing 'hpaiDataEndpoint' field")
}
@@ -214,8 +232,14 @@ func (m *ConnectionResponse) Serialize(writeBuffer utils.WriteBuffer) error {
// Optional Field (connectionResponseDataBlock) (Can be skipped, if the value is null)
var connectionResponseDataBlock *ConnectionResponseDataBlock = nil
if m.ConnectionResponseDataBlock != nil {
+ if pushErr := writeBuffer.PushContext("connectionResponseDataBlock"); pushErr != nil {
+ return pushErr
+ }
connectionResponseDataBlock = m.ConnectionResponseDataBlock
_connectionResponseDataBlockErr := connectionResponseDataBlock.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("connectionResponseDataBlock"); popErr != nil {
+ return popErr
+ }
if _connectionResponseDataBlockErr != nil {
return errors.Wrap(_connectionResponseDataBlockErr, "Error serializing 'connectionResponseDataBlock' field")
}
diff --git a/plc4go/internal/plc4go/s7/readwrite/model/COTPPacket.go b/plc4go/internal/plc4go/s7/readwrite/model/COTPPacket.go
index 13712f8..6406e9d 100644
--- a/plc4go/internal/plc4go/s7/readwrite/model/COTPPacket.go
+++ b/plc4go/internal/plc4go/s7/readwrite/model/COTPPacket.go
@@ -178,11 +178,17 @@ func COTPPacketParse(readBuffer utils.ReadBuffer, cotpLen uint16) (*COTPPacket,
curPos = readBuffer.GetPos() - startPos
var payload *S7Message = nil
if bool((curPos) < (cotpLen)) {
+ if pullErr := readBuffer.PullContext("payload"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := S7MessageParse(readBuffer)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'payload' field")
}
payload = CastS7Message(_val)
+ if closeErr := readBuffer.CloseContext("payload"); closeErr != nil {
+ return nil, closeErr
+ }
}
if closeErr := readBuffer.CloseContext("COTPPacket"); closeErr != nil {
@@ -243,8 +249,14 @@ func (m *COTPPacket) SerializeParent(writeBuffer utils.WriteBuffer, child ICOTPP
// Optional Field (payload) (Can be skipped, if the value is null)
var payload *S7Message = nil
if m.Payload != nil {
+ if pushErr := writeBuffer.PushContext("payload"); pushErr != nil {
+ return pushErr
+ }
payload = m.Payload
_payloadErr := payload.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("payload"); popErr != nil {
+ return popErr
+ }
if _payloadErr != nil {
return errors.Wrap(_payloadErr, "Error serializing 'payload' field")
}
diff --git a/plc4go/internal/plc4go/s7/readwrite/model/S7Message.go b/plc4go/internal/plc4go/s7/readwrite/model/S7Message.go
index 2c6d24d..e0b7bdf 100644
--- a/plc4go/internal/plc4go/s7/readwrite/model/S7Message.go
+++ b/plc4go/internal/plc4go/s7/readwrite/model/S7Message.go
@@ -202,21 +202,33 @@ func S7MessageParse(readBuffer utils.ReadBuffer) (*S7Message, error) {
// Optional Field (parameter) (Can be skipped, if a given expression evaluates to false)
var parameter *S7Parameter = nil
if bool((parameterLength) > (0)) {
+ if pullErr := readBuffer.PullContext("parameter"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := S7ParameterParse(readBuffer, messageType)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'parameter' field")
}
parameter = CastS7Parameter(_val)
+ if closeErr := readBuffer.CloseContext("parameter"); closeErr != nil {
+ return nil, closeErr
+ }
}
// Optional Field (payload) (Can be skipped, if a given expression evaluates to false)
var payload *S7Payload = nil
if bool((payloadLength) > (0)) {
+ if pullErr := readBuffer.PullContext("payload"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := S7PayloadParse(readBuffer, messageType, (parameter))
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'payload' field")
}
payload = CastS7Payload(_val)
+ if closeErr := readBuffer.CloseContext("payload"); closeErr != nil {
+ return nil, closeErr
+ }
}
if closeErr := readBuffer.CloseContext("S7Message"); closeErr != nil {
@@ -289,8 +301,14 @@ func (m *S7Message) SerializeParent(writeBuffer utils.WriteBuffer, child IS7Mess
// Optional Field (parameter) (Can be skipped, if the value is null)
var parameter *S7Parameter = nil
if m.Parameter != nil {
+ if pushErr := writeBuffer.PushContext("parameter"); pushErr != nil {
+ return pushErr
+ }
parameter = m.Parameter
_parameterErr := parameter.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("parameter"); popErr != nil {
+ return popErr
+ }
if _parameterErr != nil {
return errors.Wrap(_parameterErr, "Error serializing 'parameter' field")
}
@@ -299,8 +317,14 @@ func (m *S7Message) SerializeParent(writeBuffer utils.WriteBuffer, child IS7Mess
// Optional Field (payload) (Can be skipped, if the value is null)
var payload *S7Payload = nil
if m.Payload != nil {
+ if pushErr := writeBuffer.PushContext("payload"); pushErr != nil {
+ return pushErr
+ }
payload = m.Payload
_payloadErr := payload.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("payload"); popErr != nil {
+ return popErr
+ }
if _payloadErr != nil {
return errors.Wrap(_payloadErr, "Error serializing 'payload' field")
}
diff --git a/plc4go/internal/plc4go/s7/readwrite/model/S7PayloadUserDataItemCpuFunctionMsgSubscription.go b/plc4go/internal/plc4go/s7/readwrite/model/S7PayloadUserDataItemCpuFunctionMsgSubscription.go
index 8df460f..12456db 100644
--- a/plc4go/internal/plc4go/s7/readwrite/model/S7PayloadUserDataItemCpuFunctionMsgSubscription.go
+++ b/plc4go/internal/plc4go/s7/readwrite/model/S7PayloadUserDataItemCpuFunctionMsgSubscription.go
@@ -165,11 +165,17 @@ func S7PayloadUserDataItemCpuFunctionMsgSubscriptionParse(readBuffer utils.ReadB
// Optional Field (Alarmtype) (Can be skipped, if a given expression evaluates to false)
var Alarmtype *AlarmStateType = nil
if bool((Subscription) >= (128)) {
+ if pullErr := readBuffer.PullContext("Alarmtype"); pullErr != nil {
+ return nil, pullErr
+ }
_val, _err := AlarmStateTypeParse(readBuffer)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'Alarmtype' field")
}
Alarmtype = &_val
+ if closeErr := readBuffer.CloseContext("Alarmtype"); closeErr != nil {
+ return nil, closeErr
+ }
}
// Optional Field (Reserve) (Can be skipped, if a given expression evaluates to false)
@@ -229,8 +235,14 @@ func (m *S7PayloadUserDataItemCpuFunctionMsgSubscription) Serialize(writeBuffer
// Optional Field (Alarmtype) (Can be skipped, if the value is null)
var Alarmtype *AlarmStateType = nil
if m.Alarmtype != nil {
+ if pushErr := writeBuffer.PushContext("Alarmtype"); pushErr != nil {
+ return pushErr
+ }
Alarmtype = m.Alarmtype
_AlarmtypeErr := Alarmtype.Serialize(writeBuffer)
+ if popErr := writeBuffer.PopContext("Alarmtype"); popErr != nil {
+ return popErr
+ }
if _AlarmtypeErr != nil {
return errors.Wrap(_AlarmtypeErr, "Error serializing 'Alarmtype' field")
}
diff --git a/plc4go/internal/plc4go/s7/s7Io_test.go b/plc4go/internal/plc4go/s7/s7Io_test.go
index f9b2123..8467f43 100644
--- a/plc4go/internal/plc4go/s7/s7Io_test.go
+++ b/plc4go/internal/plc4go/s7/s7Io_test.go
@@ -20,6 +20,7 @@
package s7
import (
+ "fmt"
"github.com/apache/plc4x/plc4go/internal/plc4go/s7/readwrite/model"
"github.com/apache/plc4x/plc4go/internal/plc4go/spi/utils"
"reflect"
@@ -30,6 +31,7 @@ import (
func TestS7MessageBytes(t *testing.T) {
type debuggable interface {
utils.Serializable
+ fmt.Stringer
}
type args struct {
debuggable debuggable
@@ -37,7 +39,6 @@ func TestS7MessageBytes(t *testing.T) {
tests := []struct {
name string
args args
- wantString string
wantStringSerialized string
wantStringSerializedCompact string
wantStringXml string
@@ -70,47 +71,10 @@ func TestS7MessageBytes(t *testing.T) {
),
),
},
- wantString: `
-╔═TPKTPacket══════════════════════════════════════════════════════════════════════════════════════════════════════════╗
-║╔═ProtocolId╗╔═reserved╗╔═Len═════╗ ║
-║║ 0x03 3 ║║ 0x00 0 ║║0x001d 29║ ║
-║╚═══════════╝╚═════════╝╚═════════╝ ║
-║╔═COTPPacket/COTPPacketData/payload═════════════════════════════════════════════════════════════════════════════════╗║
-║║╔═HeaderLength╗╔═TpduCode╗╔═Eot════╗╔═TpduRef╗╔═Parameters═════════════════════════════════════════════════╗ ║║
-║║║ 0x05 5 ║║0xf0 240 ║║b0 false║║0x0d 13 ║║╔═COTPParameter/COTPParameterTpduSize══════════════════════╗║ ║║
-║║╚═════════════╝╚═════════╝╚════════╝╚════════╝║║╔═ParameterType╗╔═ParameterLength╗╔═COTPTpduSize/tpduSize╗║║ ║║
-║║ ║║║ 0xc0 192 ║║ 0x01 1 ║║ 0x0c SIZE_4096 ║║║ ║║
-║║ ║║╚══════════════╝╚════════════════╝╚══════════════════════╝║║ ║║
-║║ ║╚══════════════════════════════════════════════════════════╝║ ║║
-║║ ╚════════════════════════════════════════════════════════════╝ ║║
-║║╔═S7Message/S7MessageResponseData/payload═════════════════════════════════════════════════════════════════════════╗║║
-║║║╔═ProtocolId╗╔═MessageType╗╔═reserved╗╔═TpduReference╗╔═ParameterLength╗╔═PayloadLength╗╔═ErrorClass╗╔═ErrorCode╗║║║
-║║║║ 0x32 50 ║║ 0x03 3 ║║0x0000 0 ║║ 0x000b 11 ║║ 0x0002 2 ║║ 0x0005 5 ║║ 0x00 0 ║║ 0x00 0 ║║║║
-║║║╚═══════════╝╚════════════╝╚═════════╝╚══════════════╝╚════════════════╝╚══════════════╝╚═══════════╝╚══════════╝║║║
-║║║╔═S7Parameter/S7ParameterReadVarResponse/parameter╗ ║║║
-║║║║ ╔═ParameterType╗╔═NumItems╗ ║ ║║║
-║║║║ ║ 0x04 4 ║║ 0x01 1 ║ ║ ║║║
-║║║║ ╚══════════════╝╚═════════╝ ║ ║║║
-║║║╚═════════════════════════════════════════════════╝ ║║║
-║║║╔═S7Payload/S7PayloadReadVarResponse/payload════════════════════════════════════════════════════════════════╗ ║║║
-║║║║╔═Items═══════════════════════════════════════════════════════════════════════════════════════════════════╗║ ║║║
-║║║║║╔═S7VarPayloadDataItem══════════════════════════════════════════════════════════════════════════════════╗║║ ║║║
-║║║║║║╔═DataTransportErrorCode/returnCode╗╔═DataTransportSize/transportSize╗╔═DataLength╗╔═Data═══╗╔═padding╗║║║ ║║║
-║║║║║║║ 0xff OK ║║ 0x03 BIT ║║ 0x0001 1 ║║╔══════╗║║ 0x00 0 ║║║║ ║║║
-║║║║║║╚══════════════════════════════════╝╚════════════════════════════════╝╚═══════════╝║║0x01 1║║╚════════╝║║║ ║║║
-║║║║║║ ║╚══════╝║ ║║║ ║║║
-║║║║║║ ╚════════╝ ║║║ ║║║
-║║║║║╚═══════════════════════════════════════════════════════════════════════════════════════════════════════╝║║ ║║║
-║║║║╚═════════════════════════════════════════════════════════════════════════════════════════════════════════╝║ ║║║
-║║║╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════╝ ║║║
-║║╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║
-║╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║
-╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
-`,
wantStringSerialized: `
╔═TPKTPacket═══════════════════════════════════════════════════════════════════════════════════════════════════════╗
║╔═protocolId╗╔═reserved╗╔═len═════╗ ║
-║║ 0x03 3 ║║ 0x00 0 ║║0x001d 29║ ║
+║║ 0x03 3 ║║ 0x00 0 ║║0x001e 30║ ║
║╚═══════════╝╚═════════╝╚═════════╝ ║
║╔═payload════════════════════════════════════════════════════════════════════════════════════════════════════════╗║
║║╔═COTPPacket═══════════════════════════════════════════════════════════════════════════════════════════════════╗║║
@@ -125,80 +89,88 @@ func TestS7MessageBytes(t *testing.T) {
║║║ ║║ ╚══════════════════════╝║║║║║
║║║ ║╚══════════════════════════════════════════════════════════╝║║║║
║║║ ╚════════════════════════════════════════════════════════════╝║║║
-║║║╔═S7Message══════════════════════════════════════════════════════════════════════════════╗ ║║║
-║║║║╔═protocolId╗╔═messageType╗╔═reserved╗╔═tpduReference╗╔═parameterLength╗╔═payloadLength╗║ ║║║
-║║║║║ 0x32 50 ║║ 0x03 3 ║║0x0000 0 ║║ 0x000b 11 ║║ 0x0002 2 ║║ 0x0005 5 ║║ ║║║
-║║║║╚═══════════╝╚════════════╝╚═════════╝╚══════════════╝╚════════════════╝╚══════════════╝║ ║║║
-║║║║╔═S7MessageResponseData═══╗╔═S7Parameter═════════════════════════════════╗ ║ ║║║
-║║║║║╔═errorClass╗╔═errorCode╗║║╔═parameterType╗╔═S7ParameterReadVarResponse╗║ ║ ║║║
-║║║║║║ 0x00 0 ║║ 0x00 0 ║║║║ 0x04 4 ║║ ╔═numItems╗ ║║ ║ ║║║
-║║║║║╚═══════════╝╚══════════╝║║╚══════════════╝║ ║ 0x01 1 ║ ║║ ║ ║║║
-║║║║╚═════════════════════════╝║ ║ ╚═════════╝ ║║ ║ ║║║
-║║║║ ║ ╚═══════════════════════════╝║ ║ ║║║
-║║║║ ╚═════════════════════════════════════════════╝ ║ ║║║
-║║║║╔═S7Payload══════════════════════════════════════════════════════════╗ ║ ║║║
-║║║║║╔═S7PayloadReadVarResponse═════════════════════════════════════════╗║ ║ ║║║
-║║║║║║╔═items══════════════════════════════════════════════════════════╗║║ ║ ║║║
-║║║║║║║╔═S7VarPayloadDataItem═════════════════════════════════════════╗║║║ ║ ║║║
-║║║║║║║║╔═returnCode══════════════╗╔═transportSize══════╗╔═dataLength╗║║║║ ║ ║║║
-║║║║║║║║║╔═DataTransportErrorCode╗║║╔═DataTransportSize╗║║ 0x0001 1 ║║║║║ ║ ║║║
-║║║║║║║║║║ 0xff 255 OK ║║║║ 0x03 3 BIT ║║╚═══════════╝║║║║ ║ ║║║
-║║║║║║║║║╚═══════════════════════╝║║╚══════════════════╝║ ║║║║ ║ ║║║
-║║║║║║║║╚═════════════════════════╝╚════════════════════╝ ║║║║ ║ ║║║
-║║║║║║║║╔═data═══════════════════════════════════════╗╔═padding╗ ║║║║ ║ ║║║
-║║║║║║║║║0|01 '. '║║ ║ ║║║║ ║ ║║║
-║║║║║║║║╚════════════════════════════════════════════╝╚════════╝ ║║║║ ║ ║║║
-║║║║║║║╚══════════════════════════════════════════════════════════════╝║║║ ║ ║║║
-║║║║║║╚════════════════════════════════════════════════════════════════╝║║ ║ ║║║
-║║║║║╚══════════════════════════════════════════════════════════════════╝║ ║ ║║║
-║║║║╚════════════════════════════════════════════════════════════════════╝ ║ ║║║
-║║║╚════════════════════════════════════════════════════════════════════════════════════════╝ ║║║
+║║║╔═payload══════════════════════════════════════════════════════════════════════════════════╗ ║║║
+║║║║╔═S7Message══════════════════════════════════════════════════════════════════════════════╗║ ║║║
+║║║║║╔═protocolId╗╔═messageType╗╔═reserved╗╔═tpduReference╗╔═parameterLength╗╔═payloadLength╗║║ ║║║
+║║║║║║ 0x32 50 ║║ 0x03 3 ║║0x0000 0 ║║ 0x000b 11 ║║ 0x0002 2 ║║ 0x0006 6 ║║║ ║║║
+║║║║║╚═══════════╝╚════════════╝╚═════════╝╚══════════════╝╚════════════════╝╚══════════════╝║║ ║║║
+║║║║║╔═S7MessageResponseData═══╗╔═parameter═════════════════════════════════════╗ ║║ ║║║
+║║║║║║╔═errorClass╗╔═errorCode╗║║╔═S7Parameter═════════════════════════════════╗║ ║║ ║║║
+║║║║║║║ 0x00 0 ║║ 0x00 0 ║║║║╔═parameterType╗╔═S7ParameterReadVarResponse╗║║ ║║ ║║║
+║║║║║║╚═══════════╝╚══════════╝║║║║ 0x04 4 ║║ ╔═numItems╗ ║║║ ║║ ║║║
+║║║║║╚═════════════════════════╝║║╚══════════════╝║ ║ 0x01 1 ║ ║║║ ║║ ║║║
+║║║║║ ║║ ║ ╚═════════╝ ║║║ ║║ ║║║
+║║║║║ ║║ ╚═══════════════════════════╝║║ ║║ ║║║
+║║║║║ ║╚═════════════════════════════════════════════╝║ ║║ ║║║
+║║║║║ ╚═══════════════════════════════════════════════╝ ║║ ║║║
+║║║║║╔═payload══════════════════════════════════════════════════════════════╗ ║║ ║║║
+║║║║║║╔═S7Payload══════════════════════════════════════════════════════════╗║ ║║ ║║║
+║║║║║║║╔═S7PayloadReadVarResponse═════════════════════════════════════════╗║║ ║║ ║║║
+║║║║║║║║╔═items══════════════════════════════════════════════════════════╗║║║ ║║ ║║║
+║║║║║║║║║╔═S7VarPayloadDataItem═════════════════════════════════════════╗║║║║ ║║ ║║║
+║║║║║║║║║║╔═returnCode══════════════╗╔═transportSize══════╗╔═dataLength╗║║║║║ ║║ ║║║
+║║║║║║║║║║║╔═DataTransportErrorCode╗║║╔═DataTransportSize╗║║ 0x0001 1 ║║║║║║ ║║ ║║║
+║║║║║║║║║║║║ 0xff 255 OK ║║║║ 0x03 3 BIT ║║╚═══════════╝║║║║║ ║║ ║║║
+║║║║║║║║║║║╚═══════════════════════╝║║╚══════════════════╝║ ║║║║║ ║║ ║║║
+║║║║║║║║║║╚═════════════════════════╝╚════════════════════╝ ║║║║║ ║║ ║║║
+║║║║║║║║║║╔═data═══════════════════════════════════════╗╔═padding╗ ║║║║║ ║║ ║║║
+║║║║║║║║║║║0|01 '. '║║╔══════╗║ ║║║║║ ║║ ║║║
+║║║║║║║║║║╚════════════════════════════════════════════╝║║0x00 0║║ ║║║║║ ║║ ║║║
+║║║║║║║║║║ ║╚══════╝║ ║║║║║ ║║ ║║║
+║║║║║║║║║║ ╚════════╝ ║║║║║ ║║ ║║║
+║║║║║║║║║╚══════════════════════════════════════════════════════════════╝║║║║ ║║ ║║║
+║║║║║║║║╚════════════════════════════════════════════════════════════════╝║║║ ║║ ║║║
+║║║║║║║╚══════════════════════════════════════════════════════════════════╝║║ ║║ ║║║
+║║║║║║╚════════════════════════════════════════════════════════════════════╝║ ║║ ║║║
+║║║║║╚══════════════════════════════════════════════════════════════════════╝ ║║ ║║║
+║║║║╚════════════════════════════════════════════════════════════════════════════════════════╝║ ║║║
+║║║╚══════════════════════════════════════════════════════════════════════════════════════════╝ ║║║
║║╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║
║╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║
╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
`,
wantStringSerializedCompact: `
-╔═TPKTPacket══════════════════════════════════════════════════════════════════════════════════════════════════╗
-║╔═protocolId╗╔═reserved╗╔═len═════╗ ║
-║║ 0x03 3 ║║ 0x00 0 ║║0x001d 29║ ║
-║╚═══════════╝╚═════════╝╚═════════╝ ║
-║╔═payload/COTPPacket════════════════════════════════════════════════════════════════════════════════════════╗║
-║║╔═headerLength╗╔═tpduCode╗╔═COTPPacketData═════╗ ║║
-║║║ 0x05 5 ║║0xf0 240 ║║╔═eot════╗╔═tpduRef╗║ ║║
-║║╚═════════════╝╚═════════╝║║b0 false║║ 0xd 13 ║║ ║║
-║║ ║╚════════╝╚════════╝║ ║║
-║║ ╚════════════════════╝ ║║
-║║╔═parameters/COTPParameter════════════════════════════════════════════════════════════╗ ║║
-║║║╔═parameterType╗╔═parameterLength╗╔═COTPParameterTpduSize/tpduSize/COTPTpduSize═════╗║ ║║
-║║║║ 0xc0 192 ║║ 0x01 1 ║║ 0x0c 12 SIZE_4096 ║║ ║║
-║║║╚══════════════╝╚════════════════╝╚═════════════════════════════════════════════════╝║ ║║
-║║╚═════════════════════════════════════════════════════════════════════════════════════╝ ║║
-║║╔═S7Message═══════════════════════════════════════════════════════════════════════════════════════════════╗║║
-║║║╔═protocolId╗╔═messageType╗╔═reserved╗╔═tpduReference╗╔═parameterLength╗╔═payloadLength╗ ║║║
-║║║║ 0x32 50 ║║ 0x03 3 ║║0x0000 0 ║║ 0x000b 11 ║║ 0x0002 2 ║║ 0x0005 5 ║ ║║║
-║║║╚═══════════╝╚════════════╝╚═════════╝╚══════════════╝╚════════════════╝╚══════════════╝ ║║║
-║║║╔═S7MessageResponseData═══╗╔═S7Parameter═════════════════════════════════════════════╗ ║║║
-║║║║╔═errorClass╗╔═errorCode╗║║╔═parameterType╗╔═S7ParameterReadVarResponse/numItems═══╗║ ║║║
-║║║║║ 0x00 0 ║║ 0x00 0 ║║║║ 0x04 4 ║║ 0x01 1 ║║ ║║║
-║║║║╚═══════════╝╚══════════╝║║╚══════════════╝╚═══════════════════════════════════════╝║ ║║║
-║║║╚═════════════════════════╝╚═════════════════════════════════════════════════════════╝ ║║║
-║║║╔═S7Payload/S7PayloadReadVarResponse/items/S7VarPayloadDataItem═════════════════════════════════════════╗║║║
-║║║║╔═returnCode/DataTransportErrorCode════════════╗╔═transportSize/DataTransportSize════════╗╔═dataLength╗║║║║
-║║║║║ 0xff 255 OK ║║ 0x03 3 BIT ║║ 0x0001 1 ║║║║║
-║║║║╚══════════════════════════════════════════════╝╚════════════════════════════════════════╝╚═══════════╝║║║║
-║║║║╔═data═══════════════════════════════════════╗ ║║║║
-║║║║║0|01 '. '║ ║║║║
-║║║║╚════════════════════════════════════════════╝ ║║║║
-║║║╚═══════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║
-║║╚═════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║
-║╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════╝║
-╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
+╔═TPKTPacket═════════════════════════════════════════════════════════════════════════════════════╗
+║╔═protocolId╗╔═reserved╗╔═len═════╗ ║
+║║ 0x03 3 ║║ 0x00 0 ║║0x001e 30║ ║
+║╚═══════════╝╚═════════╝╚═════════╝ ║
+║╔═payload/COTPPacket═══════════════════════════════════════════════════════════════════════════╗║
+║║╔═headerLength╗╔═tpduCode╗╔═COTPPacketData═════╗ ║║
+║║║ 0x05 5 ║║0xf0 240 ║║╔═eot════╗╔═tpduRef╗║ ║║
+║║╚═════════════╝╚═════════╝║║b0 false║║ 0xd 13 ║║ ║║
+║║ ║╚════════╝╚════════╝║ ║║
+║║ ╚════════════════════╝ ║║
+║║╔═parameters/COTPParameter════════════════════════════════════════════════════════════╗ ║║
+║║║╔═parameterType╗╔═parameterLength╗╔═COTPParameterTpduSize/tpduSize/COTPTpduSize═════╗║ ║║
+║║║║ 0xc0 192 ║║ 0x01 1 ║║ 0x0c 12 SIZE_4096 ║║ ║║
+║║║╚══════════════╝╚════════════════╝╚═════════════════════════════════════════════════╝║ ║║
+║║╚═════════════════════════════════════════════════════════════════════════════════════╝ ║║
+║║╔═payload/S7Message══════════════════════════════════════════════════════════════════════════╗║║
+║║║╔═protocolId╗╔═messageType╗╔═reserved╗╔═tpduReference╗╔═parameterLength╗╔═payloadLength╗ ║║║
+║║║║ 0x32 50 ║║ 0x03 3 ║║0x0000 0 ║║ 0x000b 11 ║║ 0x0002 2 ║║ 0x0006 6 ║ ║║║
+║║║╚═══════════╝╚════════════╝╚═════════╝╚══════════════╝╚════════════════╝╚══════════════╝ ║║║
+║║║╔═S7MessageResponseData═══╗╔═parameter/S7Parameter═══════════════════════════════════╗ ║║║
+║║║║╔═errorClass╗╔═errorCode╗║║╔═parameterType╗╔═S7ParameterReadVarResponse/numItems═══╗║ ║║║
+║║║║║ 0x00 0 ║║ 0x00 0 ║║║║ 0x04 4 ║║ 0x01 1 ║║ ║║║
+║║║║╚═══════════╝╚══════════╝║║╚══════════════╝╚═══════════════════════════════════════╝║ ║║║
+║║║╚═════════════════════════╝╚═════════════════════════════════════════════════════════╝ ║║║
+║║║╔═payload/S7Payload/S7PayloadReadVarResponse/items/S7VarPayloadDataItem════════════════════╗║║║
+║║║║╔═returnCode/DataTransportErrorCode════════════╗╔═transportSize/DataTransportSize════════╗║║║║
+║║║║║ 0xff 255 OK ║║ 0x03 3 BIT ║║║║║
+║║║║╚══════════════════════════════════════════════╝╚════════════════════════════════════════╝║║║║
+║║║║╔═dataLength╗╔═data═══════════════════════════════════════╗╔═padding/╗ ║║║║
+║║║║║ 0x0001 1 ║║0|01 '. '║║ 0x00 0 ║ ║║║║
+║║║║╚═══════════╝╚════════════════════════════════════════════╝╚═════════╝ ║║║║
+║║║╚══════════════════════════════════════════════════════════════════════════════════════════╝║║║
+║║╚════════════════════════════════════════════════════════════════════════════════════════════╝║║
+║╚══════════════════════════════════════════════════════════════════════════════════════════════╝║
+╚════════════════════════════════════════════════════════════════════════════════════════════════╝
`,
wantStringXml: `
<TPKTPacket>
<protocolId dataType="uint" bitLength="8">3</protocolId>
<reserved dataType="uint" bitLength="8">0</reserved>
- <len dataType="uint" bitLength="16">29</len>
+ <len dataType="uint" bitLength="16">30</len>
<payload>
<COTPPacket>
<headerLength dataType="uint" bitLength="8">5</headerLength>
@@ -225,7 +197,7 @@ func TestS7MessageBytes(t *testing.T) {
<reserved dataType="uint" bitLength="16">0</reserved>
<tpduReference dataType="uint" bitLength="16">11</tpduReference>
<parameterLength dataType="uint" bitLength="16">2</parameterLength>
- <payloadLength dataType="uint" bitLength="16">5</payloadLength>
+ <payloadLength dataType="uint" bitLength="16">6</payloadLength>
<S7MessageResponseData>
<errorClass dataType="uint" bitLength="8">0</errorClass>
<errorCode dataType="uint" bitLength="8">0</errorCode>
@@ -319,7 +291,7 @@ func TestS7MessageBytes(t *testing.T) {
{
"value__plc4x_dataType": "uint",
"value__plc4x_bitLength": 8,
- "": 0
+ "value": 0
}
],
"returnCode": {
@@ -443,96 +415,99 @@ func TestS7MessageBytes(t *testing.T) {
),
),
},
- wantString: `
-TBD
-`,
wantStringSerialized: `
-╔═TPKTPacket═══════════════════════════════════════════════════════════════════════════════════════════════════════╗
-║╔═protocolId╗╔═reserved╗╔═len══════╗ ║
-║║ 0x03 3 ║║ 0x00 0 ║║0x0066 102║ ║
-║╚═══════════╝╚═════════╝╚══════════╝ ║
-║╔═payload════════════════════════════════════════════════════════════════════════════════════════════════════════╗║
-║║╔═COTPPacket═══════════════════════════════════════════════════════════════════════════════════════════════════╗║║
-║║║╔═headerLength╗╔═tpduCode╗╔═COTPPacketData═════╗╔═parameters═════════════════════════════════════════════════╗║║║
-║║║║ 0x05 5 ║║0xf0 240 ║║╔═eot════╗╔═tpduRef╗║║╔═COTPParameter════════════════════════════════════════════╗║║║║
-║║║╚═════════════╝╚═════════╝║║b0 false║║ 0xd 13 ║║║║╔═parameterType╗╔═parameterLength╗╔═COTPParameterTpduSize╗║║║║║
-║║║ ║╚════════╝╚════════╝║║║║ 0xc0 192 ║║ 0x01 1 ║║╔═tpduSize══════════╗ ║║║║║║
-║║║ ╚════════════════════╝║║╚══════════════╝╚════════════════╝║║╔═COTPTpduSize════╗║ ║║║║║║
-║║║ ║║ ║║║0x0c 12 SIZE_4096║║ ║║║║║║
-║║║ ║║ ║║╚═════════════════╝║ ║║║║║║
-║║║ ║║ ║╚═══════════════════╝ ║║║║║║
-║║║ ║║ ╚══════════════════════╝║║║║║
-║║║ ║╚══════════════════════════════════════════════════════════╝║║║║
-║║║ ╚════════════════════════════════════════════════════════════╝║║║
-║║║╔═S7Message══════════════════════════════════════════════════════════════════════════════════════════════════╗║║║
-║║║║╔═protocolId╗╔═messageType╗╔═reserved╗╔═tpduReference╗╔═parameterLength╗╔═payloadLength╗╔═S7MessageRequest╗ ║║║║
-║║║║║ 0x32 50 ║║ 0x01 1 ║║0x0000 0 ║║ 0x000d 13 ║║ 0x000e 14 ║║ 0x0044 68 ║║ ║ ║║║║
-║║║║╚═══════════╝╚════════════╝╚═════════╝╚══════════════╝╚════════════════╝╚══════════════╝╚═════════════════╝ ║║║║
-║║║║╔═S7Parameter══════════════════════════════════════════════════════════════════════════════════════════════╗║║║║
-║║║║║╔═parameterType╗ ║║║║║
-║║║║║║ 0x05 5 ║ ║║║║║
-║║║║║╚══════════════╝ ║║║║║
-║║║║║╔═S7ParameterWriteVarRequest═════════════════════════════════════════════════════════════════════════════╗║║║║║
-║║║║║║╔═numItems╗ ║║║║║║
-║║║║║║║ 0x01 1 ║ ║║║║║║
-║║║║║║╚═════════╝ ║║║║║║
-║║║║║║╔═items════════════════════════════════════════════════════════════════════════════════════════════════╗║║║║║║
-║║║║║║║╔═S7VarRequestParameterItem══════════════════════════════════════════════════════════════════════════╗║║║║║║║
-║║║║║║║║╔═itemType╗ ║║║║║║║║
-║║║║║║║║║ 0x12 18 ║ ║║║║║║║║
-║║║║║║║║╚═════════╝ ║║║║║║║║
-║║║║║║║║╔═S7VarRequestParameterItemAddress═════════════════════════════════════════════════════════════════╗║║║║║║║║
-║║║║║║║║║╔═itemLength╗ ║║║║║║║║║
-║║║║║║║║║║ 0x0a 10 ║ ║║║║║║║║║
-║║║║║║║║║╚═══════════╝ ║║║║║║║║║
-║║║║║║║║║╔═address════════════════════════════════════════════════════════════════════════════════════════╗║║║║║║║║║
-║║║║║║║║║║╔═S7Address════════════════════════════════════════════════════════════════════════════════════╗║║║║║║║║║║
-║║║║║║║║║║║╔═addressType╗ ║║║║║║║║║║║
-║║║║║║║║║║║║ 0x10 16 ║ ║║║║║║║║║║║
-║║║║║║║║║║║╚════════════╝ ║║║║║║║║║║║
-║║║║║║║║║║║╔═S7AddressAny═══════════════════════════════════════════════════════════════════════════════╗║║║║║║║║║║║
-║║║║║║║║║║║║╔═transportSize══╗╔═numberOfElements╗╔═dbNumber╗╔═area════════════╗╔═reserved╗╔═byteAddress╗║║║║║║║║║║║║
-║║║║║║║║║║║║║╔═TransportSize╗║║ 0x0040 64 ║║0x000d 13║║╔═MemoryArea════╗║║ 0x0 0 ║║ 0x0000 0 ║║║║║║║║║║║║║
-║║║║║║║║║║║║║║ 0x02 2 BYTE ║║╚═════════════════╝╚═════════╝║║0x81 129 INPUTS║║╚═════════╝╚════════════╝║║║║║║║║║║║║
-║║║║║║║║║║║║║╚══════════════╝║ ║╚═══════════════╝║ ║║║║║║║║║║║║
-║║║║║║║║║║║║╚════════════════╝ ╚═════════════════╝ ║║║║║║║║║║║║
-║║║║║║║║║║║║╔═bitAddress╗ ║║║║║║║║║║║║
-║║║║║║║║║║║║║ 0x0 0 ║ ║║║║║║║║║║║║
-║║║║║║║║║║║║╚═══════════╝ ║║║║║║║║║║║║
-║║║║║║║║║║║╚════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║║║║║
-║║║║║║║║║║╚══════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║║║║
-║║║║║║║║║╚════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║║║
-║║║║║║║║╚══════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║║
-║║║║║║║╚════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║
-║║║║║║╚══════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║
-║║║║║╚════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║
-║║║║╚══════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║
-║║║║╔═S7Payload══════════════════════════════════════════════════════════════╗ ║║║║
-║║║║║╔═S7PayloadWriteVarRequest═════════════════════════════════════════════╗║ ║║║║
-║║║║║║╔═items══════════════════════════════════════════════════════════════╗║║ ║║║║
-║║║║║║║╔═S7VarPayloadDataItem═════════════════════════════════════════════╗║║║ ║║║║
-║║║║║║║║╔═returnCode══════════════╗╔═transportSize══════════╗╔═dataLength╗║║║║ ║║║║
-║║║║║║║║║╔═DataTransportErrorCode╗║║╔═DataTransportSize════╗║║0x0200 512 ║║║║║ ║║║║
-║║║║║║║║║║ 0xff 255 OK ║║║║0x04 4 BYTE_WORD_DWORD║║╚═══════════╝║║║║ ║║║║
-║║║║║║║║║╚═══════════════════════╝║║╚══════════════════════╝║ ║║║║ ║║║║
-║║║║║║║║╚═════════════════════════╝╚════════════════════════╝ ║║║║ ║║║║
-║║║║║║║║╔═data════════════════════════════════════════╗╔═padding╗ ║║║║ ║║║║
-║║║║║║║║║00|af fe af fe af fe af fe af fe '..........'║║ ║ ║║║║ ║║║║
-║║║║║║║║║10|af fe af fe af fe af fe af fe '..........'║╚════════╝ ║║║║ ║║║║
-║║║║║║║║║20|af fe af fe af fe af fe af fe '..........'║ ║║║║ ║║║║
-║║║║║║║║║30|af fe af fe af fe af fe af fe '..........'║ ║║║║ ║║║║
-║║║║║║║║║40|af fe af fe af fe af fe af fe '..........'║ ║║║║ ║║║║
-║║║║║║║║║50|af fe af fe af fe af fe af fe '..........'║ ║║║║ ║║║║
-║║║║║║║║║60|af fe af fe '.... '║ ║║║║ ║║║║
-║║║║║║║║╚═════════════════════════════════════════════╝ ║║║║ ║║║║
-║║║║║║║╚══════════════════════════════════════════════════════════════════╝║║║ ║║║║
-║║║║║║╚════════════════════════════════════════════════════════════════════╝║║ ║║║║
-║║║║║╚══════════════════════════════════════════════════════════════════════╝║ ║║║║
-║║║║╚════════════════════════════════════════════════════════════════════════╝ ║║║║
-║║║╚════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║
-║║╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║
-║╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║
-╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
+╔═TPKTPacket═══════════════════════════════════════════════════════════════════════════════════════════════════════════╗
+║╔═protocolId╗╔═reserved╗╔═len══════╗ ║
+║║ 0x03 3 ║║ 0x00 0 ║║0x0066 102║ ║
+║╚═══════════╝╚═════════╝╚══════════╝ ║
+║╔═payload════════════════════════════════════════════════════════════════════════════════════════════════════════════╗║
+║║╔═COTPPacket═══════════════════════════════════════════════════════════════════════════════════════════════════════╗║║
+║║║╔═headerLength╗╔═tpduCode╗╔═COTPPacketData═════╗╔═parameters═════════════════════════════════════════════════╗ ║║║
+║║║║ 0x05 5 ║║0xf0 240 ║║╔═eot════╗╔═tpduRef╗║║╔═COTPParameter════════════════════════════════════════════╗║ ║║║
+║║║╚═════════════╝╚═════════╝║║b0 false║║ 0xd 13 ║║║║╔═parameterType╗╔═parameterLength╗╔═COTPParameterTpduSize╗║║ ║║║
+║║║ ║╚════════╝╚════════╝║║║║ 0xc0 192 ║║ 0x01 1 ║║╔═tpduSize══════════╗ ║║║ ║║║
+║║║ ╚════════════════════╝║║╚══════════════╝╚════════════════╝║║╔═COTPTpduSize════╗║ ║║║ ║║║
+║║║ ║║ ║║║0x0c 12 SIZE_4096║║ ║║║ ║║║
+║║║ ║║ ║║╚═════════════════╝║ ║║║ ║║║
+║║║ ║║ ║╚═══════════════════╝ ║║║ ║║║
+║║║ ║║ ╚══════════════════════╝║║ ║║║
+║║║ ║╚══════════════════════════════════════════════════════════╝║ ║║║
+║║║ ╚════════════════════════════════════════════════════════════╝ ║║║
+║║║╔═payload════════════════════════════════════════════════════════════════════════════════════════════════════════╗║║║
+║║║║╔═S7Message════════════════════════════════════════════════════════════════════════════════════════════════════╗║║║║
+║║║║║╔═protocolId╗╔═messageType╗╔═reserved╗╔═tpduReference╗╔═parameterLength╗╔═payloadLength╗╔═S7MessageRequest╗ ║║║║║
+║║║║║║ 0x32 50 ║║ 0x01 1 ║║0x0000 0 ║║ 0x000d 13 ║║ 0x000e 14 ║║ 0x0044 68 ║║ ║ ║║║║║
+║║║║║╚═══════════╝╚════════════╝╚═════════╝╚══════════════╝╚════════════════╝╚══════════════╝╚═════════════════╝ ║║║║║
+║║║║║╔═parameter══════════════════════════════════════════════════════════════════════════════════════════════════╗║║║║║
+║║║║║║╔═S7Parameter══════════════════════════════════════════════════════════════════════════════════════════════╗║║║║║║
+║║║║║║║╔═parameterType╗ ║║║║║║║
+║║║║║║║║ 0x05 5 ║ ║║║║║║║
+║║║║║║║╚══════════════╝ ║║║║║║║
+║║║║║║║╔═S7ParameterWriteVarRequest═════════════════════════════════════════════════════════════════════════════╗║║║║║║║
+║║║║║║║║╔═numItems╗ ║║║║║║║║
+║║║║║║║║║ 0x01 1 ║ ║║║║║║║║
+║║║║║║║║╚═════════╝ ║║║║║║║║
+║║║║║║║║╔═items════════════════════════════════════════════════════════════════════════════════════════════════╗║║║║║║║║
+║║║║║║║║║╔═S7VarRequestParameterItem══════════════════════════════════════════════════════════════════════════╗║║║║║║║║║
+║║║║║║║║║║╔═itemType╗ ║║║║║║║║║║
+║║║║║║║║║║║ 0x12 18 ║ ║║║║║║║║║║
+║║║║║║║║║║╚═════════╝ ║║║║║║║║║║
+║║║║║║║║║║╔═S7VarRequestParameterItemAddress═════════════════════════════════════════════════════════════════╗║║║║║║║║║║
+║║║║║║║║║║║╔═itemLength╗ ║║║║║║║║║║║
+║║║║║║║║║║║║ 0x0a 10 ║ ║║║║║║║║║║║
+║║║║║║║║║║║╚═══════════╝ ║║║║║║║║║║║
+║║║║║║║║║║║╔═address════════════════════════════════════════════════════════════════════════════════════════╗║║║║║║║║║║║
+║║║║║║║║║║║║╔═S7Address════════════════════════════════════════════════════════════════════════════════════╗║║║║║║║║║║║║
+║║║║║║║║║║║║║╔═addressType╗ ║║║║║║║║║║║║║
+║║║║║║║║║║║║║║ 0x10 16 ║ ║║║║║║║║║║║║║
+║║║║║║║║║║║║║╚════════════╝ ║║║║║║║║║║║║║
+║║║║║║║║║║║║║╔═S7AddressAny═══════════════════════════════════════════════════════════════════════════════╗║║║║║║║║║║║║║
+║║║║║║║║║║║║║║╔═transportSize══╗╔═numberOfElements╗╔═dbNumber╗╔═area════════════╗╔═reserved╗╔═byteAddress╗║║║║║║║║║║║║║║
+║║║║║║║║║║║║║║║╔═TransportSize╗║║ 0x0040 64 ║║0x000d 13║║╔═MemoryArea════╗║║ 0x0 0 ║║ 0x0000 0 ║║║║║║║║║║║║║║║
+║║║║║║║║║║║║║║║║ 0x02 2 BYTE ║║╚═════════════════╝╚═════════╝║║0x81 129 INPUTS║║╚═════════╝╚════════════╝║║║║║║║║║║║║║║
+║║║║║║║║║║║║║║║╚══════════════╝║ ║╚═══════════════╝║ ║║║║║║║║║║║║║║
+║║║║║║║║║║║║║║╚════════════════╝ ╚═════════════════╝ ║║║║║║║║║║║║║║
+║║║║║║║║║║║║║║╔═bitAddress╗ ║║║║║║║║║║║║║║
+║║║║║║║║║║║║║║║ 0x0 0 ║ ║║║║║║║║║║║║║║
+║║║║║║║║║║║║║║╚═══════════╝ ║║║║║║║║║║║║║║
+║║║║║║║║║║║║║╚════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║║║║║║║
+║║║║║║║║║║║║╚══════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║║║║║║
+║║║║║║║║║║║╚════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║║║║║
+║║║║║║║║║║╚══════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║║║║
+║║║║║║║║║╚════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║║║
+║║║║║║║║╚══════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║║
+║║║║║║║╚════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║║
+║║║║║║╚══════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║║
+║║║║║╚════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║
+║║║║║╔═payload══════════════════════════════════════════════════════════════════╗ ║║║║║
+║║║║║║╔═S7Payload══════════════════════════════════════════════════════════════╗║ ║║║║║
+║║║║║║║╔═S7PayloadWriteVarRequest═════════════════════════════════════════════╗║║ ║║║║║
+║║║║║║║║╔═items══════════════════════════════════════════════════════════════╗║║║ ║║║║║
+║║║║║║║║║╔═S7VarPayloadDataItem═════════════════════════════════════════════╗║║║║ ║║║║║
+║║║║║║║║║║╔═returnCode══════════════╗╔═transportSize══════════╗╔═dataLength╗║║║║║ ║║║║║
+║║║║║║║║║║║╔═DataTransportErrorCode╗║║╔═DataTransportSize════╗║║0x0200 512 ║║║║║║ ║║║║║
+║║║║║║║║║║║║ 0xff 255 OK ║║║║0x04 4 BYTE_WORD_DWORD║║╚═══════════╝║║║║║ ║║║║║
+║║║║║║║║║║║╚═══════════════════════╝║║╚══════════════════════╝║ ║║║║║ ║║║║║
+║║║║║║║║║║╚═════════════════════════╝╚════════════════════════╝ ║║║║║ ║║║║║
+║║║║║║║║║║╔═data════════════════════════════════════════╗╔═padding╗ ║║║║║ ║║║║║
+║║║║║║║║║║║00|af fe af fe af fe af fe af fe '..........'║║ ║ ║║║║║ ║║║║║
+║║║║║║║║║║║10|af fe af fe af fe af fe af fe '..........'║╚════════╝ ║║║║║ ║║║║║
+║║║║║║║║║║║20|af fe af fe af fe af fe af fe '..........'║ ║║║║║ ║║║║║
+║║║║║║║║║║║30|af fe af fe af fe af fe af fe '..........'║ ║║║║║ ║║║║║
+║║║║║║║║║║║40|af fe af fe af fe af fe af fe '..........'║ ║║║║║ ║║║║║
+║║║║║║║║║║║50|af fe af fe af fe af fe af fe '..........'║ ║║║║║ ║║║║║
+║║║║║║║║║║║60|af fe af fe '.... '║ ║║║║║ ║║║║║
+║║║║║║║║║║╚═════════════════════════════════════════════╝ ║║║║║ ║║║║║
+║║║║║║║║║╚══════════════════════════════════════════════════════════════════╝║║║║ ║║║║║
+║║║║║║║║╚════════════════════════════════════════════════════════════════════╝║║║ ║║║║║
+║║║║║║║╚══════════════════════════════════════════════════════════════════════╝║║ ║║║║║
+║║║║║║╚════════════════════════════════════════════════════════════════════════╝║ ║║║║║
+║║║║║╚══════════════════════════════════════════════════════════════════════════╝ ║║║║║
+║║║║╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║
+║║║╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║
+║║╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║║
+║╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║
+╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
`,
wantStringSerializedCompact: `
╔═TPKTPacket═════════════════════════════════════════════════════════════════════════════════════════════════╗
@@ -550,11 +525,11 @@ TBD
║║║║ 0xc0 192 ║║ 0x01 1 ║║ 0x0c 12 SIZE_4096 ║║ ║║
║║║╚══════════════╝╚════════════════╝╚═════════════════════════════════════════════════╝║ ║║
║║╚═════════════════════════════════════════════════════════════════════════════════════╝ ║║
-║║╔═S7Message══════════════════════════════════════════════════════════════════════════════════════════════╗║║
+║║╔═payload/S7Message══════════════════════════════════════════════════════════════════════════════════════╗║║
║║║╔═protocolId╗╔═messageType╗╔═reserved╗╔═tpduReference╗╔═parameterLength╗╔═payloadLength╗ ║║║
║║║║ 0x32 50 ║║ 0x01 1 ║║0x0000 0 ║║ 0x000d 13 ║║ 0x000e 14 ║║ 0x0044 68 ║ ║║║
║║║╚═══════════╝╚════════════╝╚═════════╝╚══════════════╝╚════════════════╝╚══════════════╝ ║║║
-║║║╔═S7Parameter══════════════════════════════════════════════════════════════════════════════════════════╗║║║
+║║║╔═parameter/S7Parameter════════════════════════════════════════════════════════════════════════════════╗║║║
║║║║╔═parameterType╗ ║║║║
║║║║║ 0x05 5 ║ ║║║║
║║║║╚══════════════╝ ║║║║
@@ -587,7 +562,7 @@ TBD
║║║║║╚══════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║║
║║║║╚════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║║
║║║╚══════════════════════════════════════════════════════════════════════════════════════════════════════╝║║║
-║║║╔═S7Payload/S7PayloadWriteVarRequest/items/S7VarPayloadDataItem═════════════════════════════════╗ ║║║
+║║║╔═payload/S7Payload/S7PayloadWriteVarRequest/items/S7VarPayloadDataItem═════════════════════════╗ ║║║
║║║║╔═returnCode/DataTransportErrorCode════════════╗╔═transportSize/DataTransportSize╗╔═dataLength╗║ ║║║
║║║║║ 0xff 255 OK ║║ 0x04 4 BYTE_WORD_DWORD ║║0x0200 512 ║║ ║║║
║║║║╚══════════════════════════════════════════════╝╚════════════════════════════════╝╚═══════════╝║ ║║║
@@ -629,64 +604,70 @@ TBD
</COTPParameterTpduSize>
</COTPParameter>
</parameters>
- <S7Message>
- <protocolId dataType="uint" bitLength="8">50</protocolId>
- <messageType dataType="uint" bitLength="8">1</messageType>
- <reserved dataType="uint" bitLength="16">0</reserved>
- <tpduReference dataType="uint" bitLength="16">13</tpduReference>
- <parameterLength dataType="uint" bitLength="16">14</parameterLength>
- <payloadLength dataType="uint" bitLength="16">68</payloadLength>
- <S7MessageRequest></S7MessageRequest>
- <S7Parameter>
- <parameterType dataType="uint" bitLength="8">5</parameterType>
- <S7ParameterWriteVarRequest>
- <numItems dataType="uint" bitLength="8">1</numItems>
- <items isList="true">
- <S7VarRequestParameterItem>
- <itemType dataType="uint" bitLength="8">18</itemType>
- <S7VarRequestParameterItemAddress>
- <itemLength dataType="uint" bitLength="8">10</itemLength>
- <address>
- <S7Address>
- <addressType dataType="uint" bitLength="8">16</addressType>
- <S7AddressAny>
- <transportSize>
- <TransportSize dataType="uint" bitLength="8" stringRepresentation="BYTE">2</TransportSize>
- </transportSize>
- <numberOfElements dataType="uint" bitLength="16">64</numberOfElements>
- <dbNumber dataType="uint" bitLength="16">13</dbNumber>
- <area>
- <MemoryArea dataType="uint" bitLength="8" stringRepresentation="INPUTS">129</MemoryArea>
- </area>
- <reserved dataType="uint" bitLength="5">0</reserved>
- <byteAddress dataType="uint" bitLength="16">0</byteAddress>
- <bitAddress dataType="uint" bitLength="3">0</bitAddress>
- </S7AddressAny>
- </S7Address>
- </address>
- </S7VarRequestParameterItemAddress>
- </S7VarRequestParameterItem>
- </items>
- </S7ParameterWriteVarRequest>
- </S7Parameter>
- <S7Payload>
- <S7PayloadWriteVarRequest>
- <items isList="true">
- <S7VarPayloadDataItem>
- <returnCode>
- <DataTransportErrorCode dataType="uint" bitLength="8" stringRepresentation="OK">255</DataTransportErrorCode>
- </returnCode>
- <transportSize>
- <DataTransportSize dataType="uint" bitLength="8" stringRepresentation="BYTE_WORD_DWORD">4</DataTransportSize>
- </transportSize>
- <dataLength dataType="uint" bitLength="16">512</dataLength>
- <data dataType="byte" bitLength="512">0xaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffe</data>
- <padding isList="true"></padding>
- </S7VarPayloadDataItem>
- </items>
- </S7PayloadWriteVarRequest>
- </S7Payload>
- </S7Message>
+ <payload>
+ <S7Message>
+ <protocolId dataType="uint" bitLength="8">50</protocolId>
+ <messageType dataType="uint" bitLength="8">1</messageType>
+ <reserved dataType="uint" bitLength="16">0</reserved>
+ <tpduReference dataType="uint" bitLength="16">13</tpduReference>
+ <parameterLength dataType="uint" bitLength="16">14</parameterLength>
+ <payloadLength dataType="uint" bitLength="16">68</payloadLength>
+ <S7MessageRequest></S7MessageRequest>
+ <parameter>
+ <S7Parameter>
+ <parameterType dataType="uint" bitLength="8">5</parameterType>
+ <S7ParameterWriteVarRequest>
+ <numItems dataType="uint" bitLength="8">1</numItems>
+ <items isList="true">
+ <S7VarRequestParameterItem>
+ <itemType dataType="uint" bitLength="8">18</itemType>
+ <S7VarRequestParameterItemAddress>
+ <itemLength dataType="uint" bitLength="8">10</itemLength>
+ <address>
+ <S7Address>
+ <addressType dataType="uint" bitLength="8">16</addressType>
+ <S7AddressAny>
+ <transportSize>
+ <TransportSize dataType="uint" bitLength="8" stringRepresentation="BYTE">2</TransportSize>
+ </transportSize>
+ <numberOfElements dataType="uint" bitLength="16">64</numberOfElements>
+ <dbNumber dataType="uint" bitLength="16">13</dbNumber>
+ <area>
+ <MemoryArea dataType="uint" bitLength="8" stringRepresentation="INPUTS">129</MemoryArea>
+ </area>
+ <reserved dataType="uint" bitLength="5">0</reserved>
+ <byteAddress dataType="uint" bitLength="16">0</byteAddress>
+ <bitAddress dataType="uint" bitLength="3">0</bitAddress>
+ </S7AddressAny>
+ </S7Address>
+ </address>
+ </S7VarRequestParameterItemAddress>
+ </S7VarRequestParameterItem>
+ </items>
+ </S7ParameterWriteVarRequest>
+ </S7Parameter>
+ </parameter>
+ <payload>
+ <S7Payload>
+ <S7PayloadWriteVarRequest>
+ <items isList="true">
+ <S7VarPayloadDataItem>
+ <returnCode>
+ <DataTransportErrorCode dataType="uint" bitLength="8" stringRepresentation="OK">255</DataTransportErrorCode>
+ </returnCode>
+ <transportSize>
+ <DataTransportSize dataType="uint" bitLength="8" stringRepresentation="BYTE_WORD_DWORD">4</DataTransportSize>
+ </transportSize>
+ <dataLength dataType="uint" bitLength="16">512</dataLength>
+ <data dataType="byte" bitLength="512">0xaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffe</data>
+ <padding isList="true"></padding>
+ </S7VarPayloadDataItem>
+ </items>
+ </S7PayloadWriteVarRequest>
+ </S7Payload>
+ </payload>
+ </S7Message>
+ </payload>
</COTPPacket>
</payload>
</TPKTPacket>
@@ -707,116 +688,6 @@ TBD
"tpduRef__plc4x_bitLength": 7,
"tpduRef__plc4x_dataType": "uint"
},
- "S7Message": {
- "S7MessageRequest": {},
- "S7Parameter": {
- "S7ParameterWriteVarRequest": {
- "items": [
- {
- "S7VarRequestParameterItem": {
- "S7VarRequestParameterItemAddress": {
- "address": {
- "S7Address": {
- "S7AddressAny": {
- "area": {
- "MemoryArea": 129,
- "MemoryArea__plc4x_bitLength": 8,
- "MemoryArea__plc4x_dataType": "uint",
- "MemoryArea__plc4x_stringRepresentation": "INPUTS"
- },
- "bitAddress": 0,
- "bitAddress__plc4x_bitLength": 3,
- "bitAddress__plc4x_dataType": "uint",
- "byteAddress": 0,
- "byteAddress__plc4x_bitLength": 16,
- "byteAddress__plc4x_dataType": "uint",
- "dbNumber": 13,
- "dbNumber__plc4x_bitLength": 16,
- "dbNumber__plc4x_dataType": "uint",
- "numberOfElements": 64,
- "numberOfElements__plc4x_bitLength": 16,
- "numberOfElements__plc4x_dataType": "uint",
- "reserved": 0,
- "reserved__plc4x_bitLength": 5,
- "reserved__plc4x_dataType": "uint",
- "transportSize": {
- "TransportSize": 2,
- "TransportSize__plc4x_bitLength": 8,
- "TransportSize__plc4x_dataType": "uint",
- "TransportSize__plc4x_stringRepresentation": "BYTE"
- }
- },
- "addressType": 16,
- "addressType__plc4x_bitLength": 8,
- "addressType__plc4x_dataType": "uint"
- }
- },
- "itemLength": 10,
- "itemLength__plc4x_bitLength": 8,
- "itemLength__plc4x_dataType": "uint"
- },
- "itemType": 18,
- "itemType__plc4x_bitLength": 8,
- "itemType__plc4x_dataType": "uint"
- }
- }
- ],
- "numItems": 1,
- "numItems__plc4x_bitLength": 8,
- "numItems__plc4x_dataType": "uint"
- },
- "parameterType": 5,
- "parameterType__plc4x_bitLength": 8,
- "parameterType__plc4x_dataType": "uint"
- },
- "S7Payload": {
- "S7PayloadWriteVarRequest": {
- "items": [
- {
- "S7VarPayloadDataItem": {
- "data": "0xaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffe",
- "dataLength": 512,
- "dataLength__plc4x_bitLength": 16,
- "dataLength__plc4x_dataType": "uint",
- "data__plc4x_bitLength": 512,
- "data__plc4x_dataType": "byte",
- "padding": [],
- "returnCode": {
- "DataTransportErrorCode": 255,
- "DataTransportErrorCode__plc4x_bitLength": 8,
- "DataTransportErrorCode__plc4x_dataType": "uint",
- "DataTransportErrorCode__plc4x_stringRepresentation": "OK"
- },
- "transportSize": {
- "DataTransportSize": 4,
- "DataTransportSize__plc4x_bitLength": 8,
- "DataTransportSize__plc4x_dataType": "uint",
- "DataTransportSize__plc4x_stringRepresentation": "BYTE_WORD_DWORD"
- }
- }
- }
- ]
- }
- },
- "messageType": 1,
- "messageType__plc4x_bitLength": 8,
- "messageType__plc4x_dataType": "uint",
- "parameterLength": 14,
- "parameterLength__plc4x_bitLength": 16,
- "parameterLength__plc4x_dataType": "uint",
- "payloadLength": 68,
- "payloadLength__plc4x_bitLength": 16,
- "payloadLength__plc4x_dataType": "uint",
- "protocolId": 50,
- "protocolId__plc4x_bitLength": 8,
- "protocolId__plc4x_dataType": "uint",
- "reserved": 0,
- "reserved__plc4x_bitLength": 16,
- "reserved__plc4x_dataType": "uint",
- "tpduReference": 13,
- "tpduReference__plc4x_bitLength": 16,
- "tpduReference__plc4x_dataType": "uint"
- },
"headerLength": 5,
"headerLength__plc4x_bitLength": 8,
"headerLength__plc4x_dataType": "uint",
@@ -840,6 +711,122 @@ TBD
}
}
],
+ "payload": {
+ "S7Message": {
+ "S7MessageRequest": {},
+ "messageType": 1,
+ "messageType__plc4x_bitLength": 8,
+ "messageType__plc4x_dataType": "uint",
+ "parameter": {
+ "S7Parameter": {
+ "S7ParameterWriteVarRequest": {
+ "items": [
+ {
+ "S7VarRequestParameterItem": {
+ "S7VarRequestParameterItemAddress": {
+ "address": {
+ "S7Address": {
+ "S7AddressAny": {
+ "area": {
+ "MemoryArea": 129,
+ "MemoryArea__plc4x_bitLength": 8,
+ "MemoryArea__plc4x_dataType": "uint",
+ "MemoryArea__plc4x_stringRepresentation": "INPUTS"
+ },
+ "bitAddress": 0,
+ "bitAddress__plc4x_bitLength": 3,
+ "bitAddress__plc4x_dataType": "uint",
+ "byteAddress": 0,
+ "byteAddress__plc4x_bitLength": 16,
+ "byteAddress__plc4x_dataType": "uint",
+ "dbNumber": 13,
+ "dbNumber__plc4x_bitLength": 16,
+ "dbNumber__plc4x_dataType": "uint",
+ "numberOfElements": 64,
+ "numberOfElements__plc4x_bitLength": 16,
+ "numberOfElements__plc4x_dataType": "uint",
+ "reserved": 0,
+ "reserved__plc4x_bitLength": 5,
+ "reserved__plc4x_dataType": "uint",
+ "transportSize": {
+ "TransportSize": 2,
+ "TransportSize__plc4x_bitLength": 8,
+ "TransportSize__plc4x_dataType": "uint",
+ "TransportSize__plc4x_stringRepresentation": "BYTE"
+ }
+ },
+ "addressType": 16,
+ "addressType__plc4x_bitLength": 8,
+ "addressType__plc4x_dataType": "uint"
+ }
+ },
+ "itemLength": 10,
+ "itemLength__plc4x_bitLength": 8,
+ "itemLength__plc4x_dataType": "uint"
+ },
+ "itemType": 18,
+ "itemType__plc4x_bitLength": 8,
+ "itemType__plc4x_dataType": "uint"
+ }
+ }
+ ],
+ "numItems": 1,
+ "numItems__plc4x_bitLength": 8,
+ "numItems__plc4x_dataType": "uint"
+ },
+ "parameterType": 5,
+ "parameterType__plc4x_bitLength": 8,
+ "parameterType__plc4x_dataType": "uint"
+ }
+ },
+ "parameterLength": 14,
+ "parameterLength__plc4x_bitLength": 16,
+ "parameterLength__plc4x_dataType": "uint",
+ "payload": {
+ "S7Payload": {
+ "S7PayloadWriteVarRequest": {
+ "items": [
+ {
+ "S7VarPayloadDataItem": {
+ "data": "0xaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffeaffe",
+ "dataLength": 512,
+ "dataLength__plc4x_bitLength": 16,
+ "dataLength__plc4x_dataType": "uint",
+ "data__plc4x_bitLength": 512,
+ "data__plc4x_dataType": "byte",
+ "padding": [],
+ "returnCode": {
+ "DataTransportErrorCode": 255,
+ "DataTransportErrorCode__plc4x_bitLength": 8,
+ "DataTransportErrorCode__plc4x_dataType": "uint",
+ "DataTransportErrorCode__plc4x_stringRepresentation": "OK"
+ },
+ "transportSize": {
+ "DataTransportSize": 4,
+ "DataTransportSize__plc4x_bitLength": 8,
+ "DataTransportSize__plc4x_dataType": "uint",
+ "DataTransportSize__plc4x_stringRepresentation": "BYTE_WORD_DWORD"
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ "payloadLength": 68,
+ "payloadLength__plc4x_bitLength": 16,
+ "payloadLength__plc4x_dataType": "uint",
+ "protocolId": 50,
+ "protocolId__plc4x_bitLength": 8,
+ "protocolId__plc4x_dataType": "uint",
+ "reserved": 0,
+ "reserved__plc4x_bitLength": 16,
+ "reserved__plc4x_dataType": "uint",
+ "tpduReference": 13,
+ "tpduReference__plc4x_bitLength": 16,
+ "tpduReference__plc4x_dataType": "uint"
+ }
+ },
"tpduCode": 240,
"tpduCode__plc4x_bitLength": 8,
"tpduCode__plc4x_dataType": "uint"
@@ -871,13 +858,12 @@ TBD
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- // TODO: reimplement String() method with serializer and box based
- /*t.Run("Simple 2 String", func(t *testing.T) {
- tt.wantString = strings.Trim(tt.wantString, "\n")
- if got := tt.args.debuggable.String(); got != tt.wantString {
- t.Errorf("String() = '\n%v\n', want '\n%v\n'", got, tt.wantString)
+ t.Run("Simple 2 String", func(t *testing.T) {
+ tt.wantStringSerializedCompact = strings.Trim(tt.wantStringSerializedCompact, "\n")
+ if got := tt.args.debuggable.String(); got != tt.wantStringSerializedCompact {
+ t.Errorf("String() = '\n%v\n', want '\n%v\n'", got, tt.wantStringSerializedCompact)
}
- })*/
+ })
t.Run("Simple 2 Box", func(t *testing.T) {
boxWriter := utils.NewBoxedWriteBuffer()
if err := tt.args.debuggable.Serialize(boxWriter); err != nil {