From 228f8f5e9e7909633adbd5aca10b6e61e554fe11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Dywicki?= Date: Sun, 11 Feb 2024 10:49:52 +0100 Subject: [PATCH] Update golang opcua structs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ɓukasz Dywicki --- .../protocols/opcua/DriverTestsuite.xml | 48 ++- .../protocols/opcua/readwrite/ParserHelper.go | 24 ++ .../opcua/readwrite/XmlParserHelper.go | 19 ++ .../opcua/readwrite/model/BinaryPayload.go | 212 ++++++++++++ .../opcua/readwrite/model/ChunkType.go | 159 +++++++++ .../readwrite/model/ExtensiblePayload.go | 223 ++++++++++++ .../opcua/readwrite/model/MessagePDU.go | 80 ++++- .../opcua/readwrite/model/MessageType.go | 183 ++++++++++ .../model/OpcuaAcknowledgeResponse.go | 188 +++-------- .../readwrite/model/OpcuaCloseRequest.go | 186 +++------- .../opcua/readwrite/model/OpcuaConstants.go | 174 ++++++++++ .../readwrite/model/OpcuaHelloRequest.go | 194 +++-------- .../readwrite/model/OpcuaMessageError.go | 51 +-- .../readwrite/model/OpcuaMessageRequest.go | 228 ++++--------- .../readwrite/model/OpcuaMessageResponse.go | 228 ++++--------- .../opcua/readwrite/model/OpcuaOpenRequest.go | 313 ++++------------- .../readwrite/model/OpcuaOpenResponse.go | 313 ++++------------- .../readwrite/model/OpcuaProtocolLimits.go | 250 ++++++++++++++ .../readwrite/model/OpenChannelMessage.go | 185 ++++++++++ .../model/OpenChannelMessageRequest.go | 319 ++++++++++++++++++ .../model/OpenChannelMessageResponse.go | 319 ++++++++++++++++++ .../opcua/readwrite/model/Payload.go | 243 +++++++++++++ .../opcua/readwrite/model/SecurityHeader.go | 200 +++++++++++ .../opcua/readwrite/model/SequenceHeader.go | 200 +++++++++++ 24 files changed, 3229 insertions(+), 1310 deletions(-) create mode 100644 plc4go/protocols/opcua/readwrite/model/BinaryPayload.go create mode 100644 plc4go/protocols/opcua/readwrite/model/ChunkType.go create mode 100644 plc4go/protocols/opcua/readwrite/model/ExtensiblePayload.go create mode 100644 plc4go/protocols/opcua/readwrite/model/MessageType.go create mode 100644 plc4go/protocols/opcua/readwrite/model/OpcuaConstants.go create mode 100644 plc4go/protocols/opcua/readwrite/model/OpcuaProtocolLimits.go create mode 100644 plc4go/protocols/opcua/readwrite/model/OpenChannelMessage.go create mode 100644 plc4go/protocols/opcua/readwrite/model/OpenChannelMessageRequest.go create mode 100644 plc4go/protocols/opcua/readwrite/model/OpenChannelMessageResponse.go create mode 100644 plc4go/protocols/opcua/readwrite/model/Payload.go create mode 100644 plc4go/protocols/opcua/readwrite/model/SecurityHeader.go create mode 100644 plc4go/protocols/opcua/readwrite/model/SequenceHeader.go diff --git a/plc4go/assets/testing/protocols/opcua/DriverTestsuite.xml b/plc4go/assets/testing/protocols/opcua/DriverTestsuite.xml index c2ad6fd086d..09dd484b99f 100644 --- a/plc4go/assets/testing/protocols/opcua/DriverTestsuite.xml +++ b/plc4go/assets/testing/protocols/opcua/DriverTestsuite.xml @@ -27,6 +27,12 @@ opcua read-write opcua + + + discovery + false + + Hello Request Response @@ -37,14 +43,20 @@ HEL + + F + + 47 - F - 47 - 0 - 65535 - 65535 - 2097152 - 64 + 0 + + + 65535 + 65535 + 2097152 + 64 + + 15 @@ -60,15 +72,21 @@ true - ACK + ACK + + F + + 24 - F - 24 - 0 - 65535 - 65535 - 2097152 - 64 + 0 + + + 65535 + 65535 + 2097152 + 64 + + diff --git a/plc4go/protocols/opcua/readwrite/ParserHelper.go b/plc4go/protocols/opcua/readwrite/ParserHelper.go index 7388cae7d53..38098869128 100644 --- a/plc4go/protocols/opcua/readwrite/ParserHelper.go +++ b/plc4go/protocols/opcua/readwrite/ParserHelper.go @@ -40,6 +40,12 @@ func (m OpcuaParserHelper) Parse(typeName string, arguments []string, io utils.R return model.ImageGIFParseWithBuffer(context.Background(), io) case "EncodedTicket": return model.EncodedTicketParseWithBuffer(context.Background(), io) + case "OpenChannelMessage": + response, err := utils.StrToBool(arguments[0]) + if err != nil { + return nil, errors.Wrap(err, "Error parsing") + } + return model.OpenChannelMessageParseWithBuffer(context.Background(), io, response) case "ImageJPG": return model.ImageJPGParseWithBuffer(context.Background(), io) case "PascalByteString": @@ -70,6 +76,8 @@ func (m OpcuaParserHelper) Parse(typeName string, arguments []string, io utils.R return model.FourByteNodeIdParseWithBuffer(context.Background(), io) case "AudioDataType": return model.AudioDataTypeParseWithBuffer(context.Background(), io) + case "SecurityHeader": + return model.SecurityHeaderParseWithBuffer(context.Background(), io) case "UserIdentityTokenDefinition": identifier, err := utils.StrToString(arguments[0]) if err != nil { @@ -80,12 +88,24 @@ func (m OpcuaParserHelper) Parse(typeName string, arguments []string, io utils.R return model.ContinuationPointParseWithBuffer(context.Background(), io) case "Variant": return model.VariantParseWithBuffer(context.Background(), io) + case "Payload": + extensible, err := utils.StrToBool(arguments[0]) + if err != nil { + return nil, errors.Wrap(err, "Error parsing") + } + byteCount, err := utils.StrToUint32(arguments[1]) + if err != nil { + return nil, errors.Wrap(err, "Error parsing") + } + return model.PayloadParseWithBuffer(context.Background(), io, extensible, byteCount) case "ExtensionObjectEncodingMask": return model.ExtensionObjectEncodingMaskParseWithBuffer(context.Background(), io) case "DurationString": return model.DurationStringParseWithBuffer(context.Background(), io) case "Structure": return model.StructureParseWithBuffer(context.Background(), io) + case "OpcuaConstants": + return model.OpcuaConstantsParseWithBuffer(context.Background(), io) case "ExtensionHeader": return model.ExtensionHeaderParseWithBuffer(context.Background(), io) case "UtcTime": @@ -98,6 +118,8 @@ func (m OpcuaParserHelper) Parse(typeName string, arguments []string, io utils.R return model.MessagePDUParseWithBuffer(context.Background(), io, response) case "Counter": return model.CounterParseWithBuffer(context.Background(), io) + case "SequenceHeader": + return model.SequenceHeaderParseWithBuffer(context.Background(), io) case "NodeId": return model.NodeIdParseWithBuffer(context.Background(), io) case "RsaEncryptedSecret": @@ -144,6 +166,8 @@ func (m OpcuaParserHelper) Parse(typeName string, arguments []string, io utils.R return model.ExtensionObjectDefinitionParseWithBuffer(context.Background(), io, identifier) case "ExpandedNodeId": return model.ExpandedNodeIdParseWithBuffer(context.Background(), io) + case "OpcuaProtocolLimits": + return model.OpcuaProtocolLimitsParseWithBuffer(context.Background(), io) case "NumericRange": return model.NumericRangeParseWithBuffer(context.Background(), io) case "SemanticVersionString": diff --git a/plc4go/protocols/opcua/readwrite/XmlParserHelper.go b/plc4go/protocols/opcua/readwrite/XmlParserHelper.go index 3ae52603572..ae7fcd295b2 100644 --- a/plc4go/protocols/opcua/readwrite/XmlParserHelper.go +++ b/plc4go/protocols/opcua/readwrite/XmlParserHelper.go @@ -50,6 +50,9 @@ func (m OpcuaXmlParserHelper) Parse(typeName string, xmlString string, parserArg return model.ImageGIFParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "EncodedTicket": return model.EncodedTicketParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) + case "OpenChannelMessage": + response := parserArguments[0] == "true" + return model.OpenChannelMessageParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString)), response) case "ImageJPG": return model.ImageJPGParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "PascalByteString": @@ -77,6 +80,8 @@ func (m OpcuaXmlParserHelper) Parse(typeName string, xmlString string, parserArg return model.FourByteNodeIdParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "AudioDataType": return model.AudioDataTypeParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) + case "SecurityHeader": + return model.SecurityHeaderParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "UserIdentityTokenDefinition": // TODO: find a way to parse the sub types var identifier string @@ -85,12 +90,22 @@ func (m OpcuaXmlParserHelper) Parse(typeName string, xmlString string, parserArg return model.ContinuationPointParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "Variant": return model.VariantParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) + case "Payload": + extensible := parserArguments[0] == "true" + parsedUint1, err := strconv.ParseUint(parserArguments[1], 10, 32) + if err != nil { + return nil, err + } + byteCount := uint32(parsedUint1) + return model.PayloadParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString)), extensible, byteCount) case "ExtensionObjectEncodingMask": return model.ExtensionObjectEncodingMaskParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "DurationString": return model.DurationStringParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "Structure": return model.StructureParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) + case "OpcuaConstants": + return model.OpcuaConstantsParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "ExtensionHeader": return model.ExtensionHeaderParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "UtcTime": @@ -100,6 +115,8 @@ func (m OpcuaXmlParserHelper) Parse(typeName string, xmlString string, parserArg return model.MessagePDUParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString)), response) case "Counter": return model.CounterParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) + case "SequenceHeader": + return model.SequenceHeaderParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "NodeId": return model.NodeIdParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "RsaEncryptedSecret": @@ -141,6 +158,8 @@ func (m OpcuaXmlParserHelper) Parse(typeName string, xmlString string, parserArg return model.ExtensionObjectDefinitionParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString)), identifier) case "ExpandedNodeId": return model.ExpandedNodeIdParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) + case "OpcuaProtocolLimits": + return model.OpcuaProtocolLimitsParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "NumericRange": return model.NumericRangeParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "SemanticVersionString": diff --git a/plc4go/protocols/opcua/readwrite/model/BinaryPayload.go b/plc4go/protocols/opcua/readwrite/model/BinaryPayload.go new file mode 100644 index 00000000000..e2028e64a38 --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/BinaryPayload.go @@ -0,0 +1,212 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + "github.com/apache/plc4x/plc4go/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// BinaryPayload is the corresponding interface of BinaryPayload +type BinaryPayload interface { + fmt.Stringer + utils.LengthAware + utils.Serializable + Payload + // GetPayload returns Payload (property field) + GetPayload() []byte +} + +// BinaryPayloadExactly can be used when we want exactly this type and not a type which fulfills BinaryPayload. +// This is useful for switch cases. +type BinaryPayloadExactly interface { + BinaryPayload + isBinaryPayload() bool +} + +// _BinaryPayload is the data-structure of this message +type _BinaryPayload struct { + *_Payload + Payload []byte +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for discriminator values. +/////////////////////// + +func (m *_BinaryPayload) GetExtensible() bool { + return bool(false) +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +func (m *_BinaryPayload) InitializeParent(parent Payload, sequenceHeader SequenceHeader) { + m.SequenceHeader = sequenceHeader +} + +func (m *_BinaryPayload) GetParent() Payload { + return m._Payload +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_BinaryPayload) GetPayload() []byte { + return m.Payload +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewBinaryPayload factory function for _BinaryPayload +func NewBinaryPayload(payload []byte, sequenceHeader SequenceHeader, byteCount uint32) *_BinaryPayload { + _result := &_BinaryPayload{ + Payload: payload, + _Payload: NewPayload(sequenceHeader, byteCount), + } + _result._Payload._PayloadChildRequirements = _result + return _result +} + +// Deprecated: use the interface for direct cast +func CastBinaryPayload(structType any) BinaryPayload { + if casted, ok := structType.(BinaryPayload); ok { + return casted + } + if casted, ok := structType.(*BinaryPayload); ok { + return *casted + } + return nil +} + +func (m *_BinaryPayload) GetTypeName() string { + return "BinaryPayload" +} + +func (m *_BinaryPayload) GetLengthInBits(ctx context.Context) uint16 { + lengthInBits := uint16(m.GetParentLengthInBits(ctx)) + + // Array field + if len(m.Payload) > 0 { + lengthInBits += 8 * uint16(len(m.Payload)) + } + + return lengthInBits +} + +func (m *_BinaryPayload) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func BinaryPayloadParse(ctx context.Context, theBytes []byte, extensible bool, byteCount uint32) (BinaryPayload, error) { + return BinaryPayloadParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), extensible, byteCount) +} + +func BinaryPayloadParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, extensible bool, byteCount uint32) (BinaryPayload, error) { + positionAware := readBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pullErr := readBuffer.PullContext("BinaryPayload"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for BinaryPayload") + } + currentPos := positionAware.GetPos() + _ = currentPos + // Byte Array field (payload) + numberOfBytespayload := int(byteCount) + payload, _readArrayErr := readBuffer.ReadByteArray("payload", numberOfBytespayload) + if _readArrayErr != nil { + return nil, errors.Wrap(_readArrayErr, "Error parsing 'payload' field of BinaryPayload") + } + + if closeErr := readBuffer.CloseContext("BinaryPayload"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for BinaryPayload") + } + + // Create a partially initialized instance + _child := &_BinaryPayload{ + _Payload: &_Payload{ + ByteCount: byteCount, + }, + Payload: payload, + } + _child._Payload._PayloadChildRequirements = _child + return _child, nil +} + +func (m *_BinaryPayload) Serialize() ([]byte, error) { + wb := utils.NewWriteBufferByteBased(utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes(context.Background())))) + if err := m.SerializeWithWriteBuffer(context.Background(), wb); err != nil { + return nil, err + } + return wb.GetBytes(), nil +} + +func (m *_BinaryPayload) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { + positionAware := writeBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + ser := func() error { + if pushErr := writeBuffer.PushContext("BinaryPayload"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for BinaryPayload") + } + + // Array Field (payload) + // Byte Array field (payload) + if err := writeBuffer.WriteByteArray("payload", m.GetPayload()); err != nil { + return errors.Wrap(err, "Error serializing 'payload' field") + } + + if popErr := writeBuffer.PopContext("BinaryPayload"); popErr != nil { + return errors.Wrap(popErr, "Error popping for BinaryPayload") + } + return nil + } + return m.SerializeParent(ctx, writeBuffer, m, ser) +} + +func (m *_BinaryPayload) isBinaryPayload() bool { + return true +} + +func (m *_BinaryPayload) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) + if err := writeBuffer.WriteSerializable(context.Background(), m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/opcua/readwrite/model/ChunkType.go b/plc4go/protocols/opcua/readwrite/model/ChunkType.go new file mode 100644 index 00000000000..3416eb42a9f --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/ChunkType.go @@ -0,0 +1,159 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + + "github.com/apache/plc4x/plc4go/spi/utils" + + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// ChunkType is an enum +type ChunkType string + +type IChunkType interface { + fmt.Stringer + utils.LengthAware + utils.Serializable +} + +const ( + ChunkType_CONTINUE ChunkType = "C" + ChunkType_FINAL ChunkType = "F" + ChunkType_ABORT ChunkType = "A" +) + +var ChunkTypeValues []ChunkType + +func init() { + _ = errors.New + ChunkTypeValues = []ChunkType{ + ChunkType_CONTINUE, + ChunkType_FINAL, + ChunkType_ABORT, + } +} + +func ChunkTypeByValue(value string) (enum ChunkType, ok bool) { + switch value { + case "A": + return ChunkType_ABORT, true + case "C": + return ChunkType_CONTINUE, true + case "F": + return ChunkType_FINAL, true + } + return "", false +} + +func ChunkTypeByName(value string) (enum ChunkType, ok bool) { + switch value { + case "ABORT": + return ChunkType_ABORT, true + case "CONTINUE": + return ChunkType_CONTINUE, true + case "FINAL": + return ChunkType_FINAL, true + } + return "", false +} + +func ChunkTypeKnows(value string) bool { + for _, typeValue := range ChunkTypeValues { + if string(typeValue) == value { + return true + } + } + return false +} + +func CastChunkType(structType any) ChunkType { + castFunc := func(typ any) ChunkType { + if sChunkType, ok := typ.(ChunkType); ok { + return sChunkType + } + return "" + } + return castFunc(structType) +} + +func (m ChunkType) GetLengthInBits(ctx context.Context) uint16 { + return 0 +} + +func (m ChunkType) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func ChunkTypeParse(ctx context.Context, theBytes []byte) (ChunkType, error) { + return ChunkTypeParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes)) +} + +func ChunkTypeParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) (ChunkType, error) { + log := zerolog.Ctx(ctx) + _ = log + val, err := readBuffer.ReadString("ChunkType", uint32(8), "UTF-8") + if err != nil { + return "", errors.Wrap(err, "error reading ChunkType") + } + if enum, ok := ChunkTypeByValue(val); !ok { + log.Debug().Interface("val", val).Msg("no value val found for ChunkType") + return ChunkType(val), nil + } else { + return enum, nil + } +} + +func (e ChunkType) Serialize() ([]byte, error) { + wb := utils.NewWriteBufferByteBased() + if err := e.SerializeWithWriteBuffer(context.Background(), wb); err != nil { + return nil, err + } + return wb.GetBytes(), nil +} + +func (e ChunkType) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { + log := zerolog.Ctx(ctx) + _ = log + return writeBuffer.WriteString("ChunkType", uint32(8), "UTF-8", string(e), utils.WithAdditionalStringRepresentation(e.PLC4XEnumName())) +} + +// PLC4XEnumName returns the name that is used in code to identify this enum +func (e ChunkType) PLC4XEnumName() string { + switch e { + case ChunkType_ABORT: + return "ABORT" + case ChunkType_CONTINUE: + return "CONTINUE" + case ChunkType_FINAL: + return "FINAL" + } + return fmt.Sprintf("Unknown(%v)", string(e)) +} + +func (e ChunkType) String() string { + return e.PLC4XEnumName() +} diff --git a/plc4go/protocols/opcua/readwrite/model/ExtensiblePayload.go b/plc4go/protocols/opcua/readwrite/model/ExtensiblePayload.go new file mode 100644 index 00000000000..247f86cfd4d --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/ExtensiblePayload.go @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + "github.com/apache/plc4x/plc4go/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// ExtensiblePayload is the corresponding interface of ExtensiblePayload +type ExtensiblePayload interface { + fmt.Stringer + utils.LengthAware + utils.Serializable + Payload + // GetPayload returns Payload (property field) + GetPayload() ExtensionObject +} + +// ExtensiblePayloadExactly can be used when we want exactly this type and not a type which fulfills ExtensiblePayload. +// This is useful for switch cases. +type ExtensiblePayloadExactly interface { + ExtensiblePayload + isExtensiblePayload() bool +} + +// _ExtensiblePayload is the data-structure of this message +type _ExtensiblePayload struct { + *_Payload + Payload ExtensionObject +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for discriminator values. +/////////////////////// + +func (m *_ExtensiblePayload) GetExtensible() bool { + return bool(true) +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +func (m *_ExtensiblePayload) InitializeParent(parent Payload, sequenceHeader SequenceHeader) { + m.SequenceHeader = sequenceHeader +} + +func (m *_ExtensiblePayload) GetParent() Payload { + return m._Payload +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_ExtensiblePayload) GetPayload() ExtensionObject { + return m.Payload +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewExtensiblePayload factory function for _ExtensiblePayload +func NewExtensiblePayload(payload ExtensionObject, sequenceHeader SequenceHeader, byteCount uint32) *_ExtensiblePayload { + _result := &_ExtensiblePayload{ + Payload: payload, + _Payload: NewPayload(sequenceHeader, byteCount), + } + _result._Payload._PayloadChildRequirements = _result + return _result +} + +// Deprecated: use the interface for direct cast +func CastExtensiblePayload(structType any) ExtensiblePayload { + if casted, ok := structType.(ExtensiblePayload); ok { + return casted + } + if casted, ok := structType.(*ExtensiblePayload); ok { + return *casted + } + return nil +} + +func (m *_ExtensiblePayload) GetTypeName() string { + return "ExtensiblePayload" +} + +func (m *_ExtensiblePayload) GetLengthInBits(ctx context.Context) uint16 { + lengthInBits := uint16(m.GetParentLengthInBits(ctx)) + + // Simple field (payload) + lengthInBits += m.Payload.GetLengthInBits(ctx) + + return lengthInBits +} + +func (m *_ExtensiblePayload) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func ExtensiblePayloadParse(ctx context.Context, theBytes []byte, extensible bool, byteCount uint32) (ExtensiblePayload, error) { + return ExtensiblePayloadParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), extensible, byteCount) +} + +func ExtensiblePayloadParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, extensible bool, byteCount uint32) (ExtensiblePayload, error) { + positionAware := readBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pullErr := readBuffer.PullContext("ExtensiblePayload"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for ExtensiblePayload") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Simple Field (payload) + if pullErr := readBuffer.PullContext("payload"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for payload") + } + _payload, _payloadErr := ExtensionObjectParseWithBuffer(ctx, readBuffer, bool(bool(false))) + if _payloadErr != nil { + return nil, errors.Wrap(_payloadErr, "Error parsing 'payload' field of ExtensiblePayload") + } + payload := _payload.(ExtensionObject) + if closeErr := readBuffer.CloseContext("payload"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for payload") + } + + if closeErr := readBuffer.CloseContext("ExtensiblePayload"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for ExtensiblePayload") + } + + // Create a partially initialized instance + _child := &_ExtensiblePayload{ + _Payload: &_Payload{ + ByteCount: byteCount, + }, + Payload: payload, + } + _child._Payload._PayloadChildRequirements = _child + return _child, nil +} + +func (m *_ExtensiblePayload) Serialize() ([]byte, error) { + wb := utils.NewWriteBufferByteBased(utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes(context.Background())))) + if err := m.SerializeWithWriteBuffer(context.Background(), wb); err != nil { + return nil, err + } + return wb.GetBytes(), nil +} + +func (m *_ExtensiblePayload) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { + positionAware := writeBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + ser := func() error { + if pushErr := writeBuffer.PushContext("ExtensiblePayload"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for ExtensiblePayload") + } + + // Simple Field (payload) + if pushErr := writeBuffer.PushContext("payload"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for payload") + } + _payloadErr := writeBuffer.WriteSerializable(ctx, m.GetPayload()) + if popErr := writeBuffer.PopContext("payload"); popErr != nil { + return errors.Wrap(popErr, "Error popping for payload") + } + if _payloadErr != nil { + return errors.Wrap(_payloadErr, "Error serializing 'payload' field") + } + + if popErr := writeBuffer.PopContext("ExtensiblePayload"); popErr != nil { + return errors.Wrap(popErr, "Error popping for ExtensiblePayload") + } + return nil + } + return m.SerializeParent(ctx, writeBuffer, m, ser) +} + +func (m *_ExtensiblePayload) isExtensiblePayload() bool { + return true +} + +func (m *_ExtensiblePayload) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) + if err := writeBuffer.WriteSerializable(context.Background(), m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/opcua/readwrite/model/MessagePDU.go b/plc4go/protocols/opcua/readwrite/model/MessagePDU.go index 8ff90105bb2..ef69fff5b34 100644 --- a/plc4go/protocols/opcua/readwrite/model/MessagePDU.go +++ b/plc4go/protocols/opcua/readwrite/model/MessagePDU.go @@ -38,6 +38,8 @@ type MessagePDU interface { GetMessageType() string // GetResponse returns Response (discriminator field) GetResponse() bool + // GetChunk returns Chunk (property field) + GetChunk() ChunkType } // MessagePDUExactly can be used when we want exactly this type and not a type which fulfills MessagePDU. @@ -50,6 +52,7 @@ type MessagePDUExactly interface { // _MessagePDU is the data-structure of this message type _MessagePDU struct { _MessagePDUChildRequirements + Chunk ChunkType } type _MessagePDUChildRequirements interface { @@ -66,16 +69,30 @@ type MessagePDUParent interface { type MessagePDUChild interface { utils.Serializable - InitializeParent(parent MessagePDU) + InitializeParent(parent MessagePDU, chunk ChunkType) GetParent() *MessagePDU GetTypeName() string MessagePDU } +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_MessagePDU) GetChunk() ChunkType { + return m.Chunk +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + // NewMessagePDU factory function for _MessagePDU -func NewMessagePDU() *_MessagePDU { - return &_MessagePDU{} +func NewMessagePDU(chunk ChunkType) *_MessagePDU { + return &_MessagePDU{Chunk: chunk} } // Deprecated: use the interface for direct cast @@ -98,6 +115,12 @@ func (m *_MessagePDU) GetParentLengthInBits(ctx context.Context) uint16 { // Discriminator Field (messageType) lengthInBits += 24 + // Simple field (chunk) + lengthInBits += 8 + + // Implicit Field (totalLength) + lengthInBits += 32 + return lengthInBits } @@ -126,10 +149,30 @@ func MessagePDUParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, return nil, errors.Wrap(_messageTypeErr, "Error parsing 'messageType' field of MessagePDU") } + // Simple Field (chunk) + if pullErr := readBuffer.PullContext("chunk"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for chunk") + } + _chunk, _chunkErr := ChunkTypeParseWithBuffer(ctx, readBuffer) + if _chunkErr != nil { + return nil, errors.Wrap(_chunkErr, "Error parsing 'chunk' field of MessagePDU") + } + chunk := _chunk + if closeErr := readBuffer.CloseContext("chunk"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for chunk") + } + + // Implicit Field (totalLength) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) + totalLength, _totalLengthErr := readBuffer.ReadUint32("totalLength", 32) + _ = totalLength + if _totalLengthErr != nil { + return nil, errors.Wrap(_totalLengthErr, "Error parsing 'totalLength' field of MessagePDU") + } + // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) type MessagePDUChildSerializeRequirement interface { MessagePDU - InitializeParent(MessagePDU) + InitializeParent(MessagePDU, ChunkType) GetParent() MessagePDU } var _childTemp any @@ -141,15 +184,15 @@ func MessagePDUParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, case messageType == "ACK" && response == bool(true): // OpcuaAcknowledgeResponse _childTemp, typeSwitchError = OpcuaAcknowledgeResponseParseWithBuffer(ctx, readBuffer, response) case messageType == "OPN" && response == bool(false): // OpcuaOpenRequest - _childTemp, typeSwitchError = OpcuaOpenRequestParseWithBuffer(ctx, readBuffer, response) + _childTemp, typeSwitchError = OpcuaOpenRequestParseWithBuffer(ctx, readBuffer, totalLength, response) case messageType == "OPN" && response == bool(true): // OpcuaOpenResponse - _childTemp, typeSwitchError = OpcuaOpenResponseParseWithBuffer(ctx, readBuffer, response) + _childTemp, typeSwitchError = OpcuaOpenResponseParseWithBuffer(ctx, readBuffer, totalLength, response) case messageType == "CLO" && response == bool(false): // OpcuaCloseRequest _childTemp, typeSwitchError = OpcuaCloseRequestParseWithBuffer(ctx, readBuffer, response) case messageType == "MSG" && response == bool(false): // OpcuaMessageRequest - _childTemp, typeSwitchError = OpcuaMessageRequestParseWithBuffer(ctx, readBuffer, response) + _childTemp, typeSwitchError = OpcuaMessageRequestParseWithBuffer(ctx, readBuffer, totalLength, response) case messageType == "MSG" && response == bool(true): // OpcuaMessageResponse - _childTemp, typeSwitchError = OpcuaMessageResponseParseWithBuffer(ctx, readBuffer, response) + _childTemp, typeSwitchError = OpcuaMessageResponseParseWithBuffer(ctx, readBuffer, totalLength, response) case messageType == "ERR" && response == bool(true): // OpcuaMessageError _childTemp, typeSwitchError = OpcuaMessageErrorParseWithBuffer(ctx, readBuffer, response) default: @@ -165,7 +208,7 @@ func MessagePDUParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, } // Finish initializing - _child.InitializeParent(_child) + _child.InitializeParent(_child, chunk) return _child, nil } @@ -189,6 +232,25 @@ func (pm *_MessagePDU) SerializeParent(ctx context.Context, writeBuffer utils.Wr return errors.Wrap(_messageTypeErr, "Error serializing 'messageType' field") } + // Simple Field (chunk) + if pushErr := writeBuffer.PushContext("chunk"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for chunk") + } + _chunkErr := writeBuffer.WriteSerializable(ctx, m.GetChunk()) + if popErr := writeBuffer.PopContext("chunk"); popErr != nil { + return errors.Wrap(popErr, "Error popping for chunk") + } + if _chunkErr != nil { + return errors.Wrap(_chunkErr, "Error serializing 'chunk' field") + } + + // Implicit Field (totalLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) + totalLength := uint32(uint32(m.GetLengthInBytes(ctx))) + _totalLengthErr := writeBuffer.WriteUint32("totalLength", 32, uint32((totalLength))) + if _totalLengthErr != nil { + return errors.Wrap(_totalLengthErr, "Error serializing 'totalLength' field") + } + // Switch field (Depending on the discriminator values, passes the serialization to a sub-type) if _typeSwitchErr := serializeChildFunction(); _typeSwitchErr != nil { return errors.Wrap(_typeSwitchErr, "Error serializing sub-type field") diff --git a/plc4go/protocols/opcua/readwrite/model/MessageType.go b/plc4go/protocols/opcua/readwrite/model/MessageType.go new file mode 100644 index 00000000000..8b525c8be76 --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/MessageType.go @@ -0,0 +1,183 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + + "github.com/apache/plc4x/plc4go/spi/utils" + + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// MessageType is an enum +type MessageType string + +type IMessageType interface { + fmt.Stringer + utils.LengthAware + utils.Serializable +} + +const ( + MessageType_HELLO MessageType = "HEL" + MessageType_ACKNOWLEDGE MessageType = "ACK" + MessageType_ERROR MessageType = "ERR" + MessageType_OPEN MessageType = "OPN" + MessageType_CLOSE MessageType = "CLO" + MessageType_MESSAGE MessageType = "MSG" +) + +var MessageTypeValues []MessageType + +func init() { + _ = errors.New + MessageTypeValues = []MessageType{ + MessageType_HELLO, + MessageType_ACKNOWLEDGE, + MessageType_ERROR, + MessageType_OPEN, + MessageType_CLOSE, + MessageType_MESSAGE, + } +} + +func MessageTypeByValue(value string) (enum MessageType, ok bool) { + switch value { + case "ACK": + return MessageType_ACKNOWLEDGE, true + case "CLO": + return MessageType_CLOSE, true + case "ERR": + return MessageType_ERROR, true + case "HEL": + return MessageType_HELLO, true + case "MSG": + return MessageType_MESSAGE, true + case "OPN": + return MessageType_OPEN, true + } + return "", false +} + +func MessageTypeByName(value string) (enum MessageType, ok bool) { + switch value { + case "ACKNOWLEDGE": + return MessageType_ACKNOWLEDGE, true + case "CLOSE": + return MessageType_CLOSE, true + case "ERROR": + return MessageType_ERROR, true + case "HELLO": + return MessageType_HELLO, true + case "MESSAGE": + return MessageType_MESSAGE, true + case "OPEN": + return MessageType_OPEN, true + } + return "", false +} + +func MessageTypeKnows(value string) bool { + for _, typeValue := range MessageTypeValues { + if string(typeValue) == value { + return true + } + } + return false +} + +func CastMessageType(structType any) MessageType { + castFunc := func(typ any) MessageType { + if sMessageType, ok := typ.(MessageType); ok { + return sMessageType + } + return "" + } + return castFunc(structType) +} + +func (m MessageType) GetLengthInBits(ctx context.Context) uint16 { + return 0 +} + +func (m MessageType) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func MessageTypeParse(ctx context.Context, theBytes []byte) (MessageType, error) { + return MessageTypeParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes)) +} + +func MessageTypeParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) (MessageType, error) { + log := zerolog.Ctx(ctx) + _ = log + val, err := readBuffer.ReadString("MessageType", uint32(24), "UTF-8") + if err != nil { + return "", errors.Wrap(err, "error reading MessageType") + } + if enum, ok := MessageTypeByValue(val); !ok { + log.Debug().Interface("val", val).Msg("no value val found for MessageType") + return MessageType(val), nil + } else { + return enum, nil + } +} + +func (e MessageType) Serialize() ([]byte, error) { + wb := utils.NewWriteBufferByteBased() + if err := e.SerializeWithWriteBuffer(context.Background(), wb); err != nil { + return nil, err + } + return wb.GetBytes(), nil +} + +func (e MessageType) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { + log := zerolog.Ctx(ctx) + _ = log + return writeBuffer.WriteString("MessageType", uint32(24), "UTF-8", string(e), utils.WithAdditionalStringRepresentation(e.PLC4XEnumName())) +} + +// PLC4XEnumName returns the name that is used in code to identify this enum +func (e MessageType) PLC4XEnumName() string { + switch e { + case MessageType_ACKNOWLEDGE: + return "ACKNOWLEDGE" + case MessageType_CLOSE: + return "CLOSE" + case MessageType_ERROR: + return "ERROR" + case MessageType_HELLO: + return "HELLO" + case MessageType_MESSAGE: + return "MESSAGE" + case MessageType_OPEN: + return "OPEN" + } + return fmt.Sprintf("Unknown(%v)", string(e)) +} + +func (e MessageType) String() string { + return e.PLC4XEnumName() +} diff --git a/plc4go/protocols/opcua/readwrite/model/OpcuaAcknowledgeResponse.go b/plc4go/protocols/opcua/readwrite/model/OpcuaAcknowledgeResponse.go index 10b3314e3db..0fe93ed6534 100644 --- a/plc4go/protocols/opcua/readwrite/model/OpcuaAcknowledgeResponse.go +++ b/plc4go/protocols/opcua/readwrite/model/OpcuaAcknowledgeResponse.go @@ -35,18 +35,10 @@ type OpcuaAcknowledgeResponse interface { utils.LengthAware utils.Serializable MessagePDU - // GetChunk returns Chunk (property field) - GetChunk() string // GetVersion returns Version (property field) - GetVersion() int32 - // GetReceiveBufferSize returns ReceiveBufferSize (property field) - GetReceiveBufferSize() int32 - // GetSendBufferSize returns SendBufferSize (property field) - GetSendBufferSize() int32 - // GetMaxMessageSize returns MaxMessageSize (property field) - GetMaxMessageSize() int32 - // GetMaxChunkCount returns MaxChunkCount (property field) - GetMaxChunkCount() int32 + GetVersion() uint32 + // GetLimits returns Limits (property field) + GetLimits() OpcuaProtocolLimits } // OpcuaAcknowledgeResponseExactly can be used when we want exactly this type and not a type which fulfills OpcuaAcknowledgeResponse. @@ -59,12 +51,8 @@ type OpcuaAcknowledgeResponseExactly interface { // _OpcuaAcknowledgeResponse is the data-structure of this message type _OpcuaAcknowledgeResponse struct { *_MessagePDU - Chunk string - Version int32 - ReceiveBufferSize int32 - SendBufferSize int32 - MaxMessageSize int32 - MaxChunkCount int32 + Version uint32 + Limits OpcuaProtocolLimits } /////////////////////////////////////////////////////////// @@ -85,7 +73,9 @@ func (m *_OpcuaAcknowledgeResponse) GetResponse() bool { /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -func (m *_OpcuaAcknowledgeResponse) InitializeParent(parent MessagePDU) {} +func (m *_OpcuaAcknowledgeResponse) InitializeParent(parent MessagePDU, chunk ChunkType) { + m.Chunk = chunk +} func (m *_OpcuaAcknowledgeResponse) GetParent() MessagePDU { return m._MessagePDU @@ -96,28 +86,12 @@ func (m *_OpcuaAcknowledgeResponse) GetParent() MessagePDU { /////////////////////// Accessors for property fields. /////////////////////// -func (m *_OpcuaAcknowledgeResponse) GetChunk() string { - return m.Chunk -} - -func (m *_OpcuaAcknowledgeResponse) GetVersion() int32 { +func (m *_OpcuaAcknowledgeResponse) GetVersion() uint32 { return m.Version } -func (m *_OpcuaAcknowledgeResponse) GetReceiveBufferSize() int32 { - return m.ReceiveBufferSize -} - -func (m *_OpcuaAcknowledgeResponse) GetSendBufferSize() int32 { - return m.SendBufferSize -} - -func (m *_OpcuaAcknowledgeResponse) GetMaxMessageSize() int32 { - return m.MaxMessageSize -} - -func (m *_OpcuaAcknowledgeResponse) GetMaxChunkCount() int32 { - return m.MaxChunkCount +func (m *_OpcuaAcknowledgeResponse) GetLimits() OpcuaProtocolLimits { + return m.Limits } /////////////////////// @@ -126,15 +100,11 @@ func (m *_OpcuaAcknowledgeResponse) GetMaxChunkCount() int32 { /////////////////////////////////////////////////////////// // NewOpcuaAcknowledgeResponse factory function for _OpcuaAcknowledgeResponse -func NewOpcuaAcknowledgeResponse(chunk string, version int32, receiveBufferSize int32, sendBufferSize int32, maxMessageSize int32, maxChunkCount int32) *_OpcuaAcknowledgeResponse { +func NewOpcuaAcknowledgeResponse(version uint32, limits OpcuaProtocolLimits, chunk ChunkType) *_OpcuaAcknowledgeResponse { _result := &_OpcuaAcknowledgeResponse{ - Chunk: chunk, - Version: version, - ReceiveBufferSize: receiveBufferSize, - SendBufferSize: sendBufferSize, - MaxMessageSize: maxMessageSize, - MaxChunkCount: maxChunkCount, - _MessagePDU: NewMessagePDU(), + Version: version, + Limits: limits, + _MessagePDU: NewMessagePDU(chunk), } _result._MessagePDU._MessagePDUChildRequirements = _result return _result @@ -158,26 +128,11 @@ func (m *_OpcuaAcknowledgeResponse) GetTypeName() string { func (m *_OpcuaAcknowledgeResponse) GetLengthInBits(ctx context.Context) uint16 { lengthInBits := uint16(m.GetParentLengthInBits(ctx)) - // Simple field (chunk) - lengthInBits += 8 - - // Implicit Field (messageSize) - lengthInBits += 32 - // Simple field (version) lengthInBits += 32 - // Simple field (receiveBufferSize) - lengthInBits += 32 - - // Simple field (sendBufferSize) - lengthInBits += 32 - - // Simple field (maxMessageSize) - lengthInBits += 32 - - // Simple field (maxChunkCount) - lengthInBits += 32 + // Simple field (limits) + lengthInBits += m.Limits.GetLengthInBits(ctx) return lengthInBits } @@ -201,54 +156,25 @@ func OpcuaAcknowledgeResponseParseWithBuffer(ctx context.Context, readBuffer uti currentPos := positionAware.GetPos() _ = currentPos - // Simple Field (chunk) - _chunk, _chunkErr := readBuffer.ReadString("chunk", uint32(8), "UTF-8") - if _chunkErr != nil { - return nil, errors.Wrap(_chunkErr, "Error parsing 'chunk' field of OpcuaAcknowledgeResponse") - } - chunk := _chunk - - // Implicit Field (messageSize) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) - messageSize, _messageSizeErr := readBuffer.ReadInt32("messageSize", 32) - _ = messageSize - if _messageSizeErr != nil { - return nil, errors.Wrap(_messageSizeErr, "Error parsing 'messageSize' field of OpcuaAcknowledgeResponse") - } - // Simple Field (version) - _version, _versionErr := readBuffer.ReadInt32("version", 32) + _version, _versionErr := readBuffer.ReadUint32("version", 32) if _versionErr != nil { return nil, errors.Wrap(_versionErr, "Error parsing 'version' field of OpcuaAcknowledgeResponse") } version := _version - // Simple Field (receiveBufferSize) - _receiveBufferSize, _receiveBufferSizeErr := readBuffer.ReadInt32("receiveBufferSize", 32) - if _receiveBufferSizeErr != nil { - return nil, errors.Wrap(_receiveBufferSizeErr, "Error parsing 'receiveBufferSize' field of OpcuaAcknowledgeResponse") + // Simple Field (limits) + if pullErr := readBuffer.PullContext("limits"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for limits") } - receiveBufferSize := _receiveBufferSize - - // Simple Field (sendBufferSize) - _sendBufferSize, _sendBufferSizeErr := readBuffer.ReadInt32("sendBufferSize", 32) - if _sendBufferSizeErr != nil { - return nil, errors.Wrap(_sendBufferSizeErr, "Error parsing 'sendBufferSize' field of OpcuaAcknowledgeResponse") - } - sendBufferSize := _sendBufferSize - - // Simple Field (maxMessageSize) - _maxMessageSize, _maxMessageSizeErr := readBuffer.ReadInt32("maxMessageSize", 32) - if _maxMessageSizeErr != nil { - return nil, errors.Wrap(_maxMessageSizeErr, "Error parsing 'maxMessageSize' field of OpcuaAcknowledgeResponse") + _limits, _limitsErr := OpcuaProtocolLimitsParseWithBuffer(ctx, readBuffer) + if _limitsErr != nil { + return nil, errors.Wrap(_limitsErr, "Error parsing 'limits' field of OpcuaAcknowledgeResponse") } - maxMessageSize := _maxMessageSize - - // Simple Field (maxChunkCount) - _maxChunkCount, _maxChunkCountErr := readBuffer.ReadInt32("maxChunkCount", 32) - if _maxChunkCountErr != nil { - return nil, errors.Wrap(_maxChunkCountErr, "Error parsing 'maxChunkCount' field of OpcuaAcknowledgeResponse") + limits := _limits.(OpcuaProtocolLimits) + if closeErr := readBuffer.CloseContext("limits"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for limits") } - maxChunkCount := _maxChunkCount if closeErr := readBuffer.CloseContext("OpcuaAcknowledgeResponse"); closeErr != nil { return nil, errors.Wrap(closeErr, "Error closing for OpcuaAcknowledgeResponse") @@ -256,13 +182,9 @@ func OpcuaAcknowledgeResponseParseWithBuffer(ctx context.Context, readBuffer uti // Create a partially initialized instance _child := &_OpcuaAcknowledgeResponse{ - _MessagePDU: &_MessagePDU{}, - Chunk: chunk, - Version: version, - ReceiveBufferSize: receiveBufferSize, - SendBufferSize: sendBufferSize, - MaxMessageSize: maxMessageSize, - MaxChunkCount: maxChunkCount, + _MessagePDU: &_MessagePDU{}, + Version: version, + Limits: limits, } _child._MessagePDU._MessagePDUChildRequirements = _child return _child, nil @@ -286,53 +208,23 @@ func (m *_OpcuaAcknowledgeResponse) SerializeWithWriteBuffer(ctx context.Context return errors.Wrap(pushErr, "Error pushing for OpcuaAcknowledgeResponse") } - // Simple Field (chunk) - chunk := string(m.GetChunk()) - _chunkErr := writeBuffer.WriteString("chunk", uint32(8), "UTF-8", (chunk)) - if _chunkErr != nil { - return errors.Wrap(_chunkErr, "Error serializing 'chunk' field") - } - - // Implicit Field (messageSize) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - messageSize := int32(int32(m.GetLengthInBytes(ctx))) - _messageSizeErr := writeBuffer.WriteInt32("messageSize", 32, int32((messageSize))) - if _messageSizeErr != nil { - return errors.Wrap(_messageSizeErr, "Error serializing 'messageSize' field") - } - // Simple Field (version) - version := int32(m.GetVersion()) - _versionErr := writeBuffer.WriteInt32("version", 32, int32((version))) + version := uint32(m.GetVersion()) + _versionErr := writeBuffer.WriteUint32("version", 32, uint32((version))) if _versionErr != nil { return errors.Wrap(_versionErr, "Error serializing 'version' field") } - // Simple Field (receiveBufferSize) - receiveBufferSize := int32(m.GetReceiveBufferSize()) - _receiveBufferSizeErr := writeBuffer.WriteInt32("receiveBufferSize", 32, int32((receiveBufferSize))) - if _receiveBufferSizeErr != nil { - return errors.Wrap(_receiveBufferSizeErr, "Error serializing 'receiveBufferSize' field") + // Simple Field (limits) + if pushErr := writeBuffer.PushContext("limits"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for limits") } - - // Simple Field (sendBufferSize) - sendBufferSize := int32(m.GetSendBufferSize()) - _sendBufferSizeErr := writeBuffer.WriteInt32("sendBufferSize", 32, int32((sendBufferSize))) - if _sendBufferSizeErr != nil { - return errors.Wrap(_sendBufferSizeErr, "Error serializing 'sendBufferSize' field") - } - - // Simple Field (maxMessageSize) - maxMessageSize := int32(m.GetMaxMessageSize()) - _maxMessageSizeErr := writeBuffer.WriteInt32("maxMessageSize", 32, int32((maxMessageSize))) - if _maxMessageSizeErr != nil { - return errors.Wrap(_maxMessageSizeErr, "Error serializing 'maxMessageSize' field") + _limitsErr := writeBuffer.WriteSerializable(ctx, m.GetLimits()) + if popErr := writeBuffer.PopContext("limits"); popErr != nil { + return errors.Wrap(popErr, "Error popping for limits") } - - // Simple Field (maxChunkCount) - maxChunkCount := int32(m.GetMaxChunkCount()) - _maxChunkCountErr := writeBuffer.WriteInt32("maxChunkCount", 32, int32((maxChunkCount))) - if _maxChunkCountErr != nil { - return errors.Wrap(_maxChunkCountErr, "Error serializing 'maxChunkCount' field") + if _limitsErr != nil { + return errors.Wrap(_limitsErr, "Error serializing 'limits' field") } if popErr := writeBuffer.PopContext("OpcuaAcknowledgeResponse"); popErr != nil { diff --git a/plc4go/protocols/opcua/readwrite/model/OpcuaCloseRequest.go b/plc4go/protocols/opcua/readwrite/model/OpcuaCloseRequest.go index 234446b357a..0c89315f09b 100644 --- a/plc4go/protocols/opcua/readwrite/model/OpcuaCloseRequest.go +++ b/plc4go/protocols/opcua/readwrite/model/OpcuaCloseRequest.go @@ -35,18 +35,10 @@ type OpcuaCloseRequest interface { utils.LengthAware utils.Serializable MessagePDU - // GetChunk returns Chunk (property field) - GetChunk() string - // GetSecureChannelId returns SecureChannelId (property field) - GetSecureChannelId() int32 - // GetSecureTokenId returns SecureTokenId (property field) - GetSecureTokenId() int32 - // GetSequenceNumber returns SequenceNumber (property field) - GetSequenceNumber() int32 - // GetRequestId returns RequestId (property field) - GetRequestId() int32 + // GetSecurityHeader returns SecurityHeader (property field) + GetSecurityHeader() SecurityHeader // GetMessage returns Message (property field) - GetMessage() ExtensionObject + GetMessage() Payload } // OpcuaCloseRequestExactly can be used when we want exactly this type and not a type which fulfills OpcuaCloseRequest. @@ -59,12 +51,8 @@ type OpcuaCloseRequestExactly interface { // _OpcuaCloseRequest is the data-structure of this message type _OpcuaCloseRequest struct { *_MessagePDU - Chunk string - SecureChannelId int32 - SecureTokenId int32 - SequenceNumber int32 - RequestId int32 - Message ExtensionObject + SecurityHeader SecurityHeader + Message Payload } /////////////////////////////////////////////////////////// @@ -85,7 +73,9 @@ func (m *_OpcuaCloseRequest) GetResponse() bool { /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -func (m *_OpcuaCloseRequest) InitializeParent(parent MessagePDU) {} +func (m *_OpcuaCloseRequest) InitializeParent(parent MessagePDU, chunk ChunkType) { + m.Chunk = chunk +} func (m *_OpcuaCloseRequest) GetParent() MessagePDU { return m._MessagePDU @@ -96,27 +86,11 @@ func (m *_OpcuaCloseRequest) GetParent() MessagePDU { /////////////////////// Accessors for property fields. /////////////////////// -func (m *_OpcuaCloseRequest) GetChunk() string { - return m.Chunk -} - -func (m *_OpcuaCloseRequest) GetSecureChannelId() int32 { - return m.SecureChannelId -} - -func (m *_OpcuaCloseRequest) GetSecureTokenId() int32 { - return m.SecureTokenId -} - -func (m *_OpcuaCloseRequest) GetSequenceNumber() int32 { - return m.SequenceNumber +func (m *_OpcuaCloseRequest) GetSecurityHeader() SecurityHeader { + return m.SecurityHeader } -func (m *_OpcuaCloseRequest) GetRequestId() int32 { - return m.RequestId -} - -func (m *_OpcuaCloseRequest) GetMessage() ExtensionObject { +func (m *_OpcuaCloseRequest) GetMessage() Payload { return m.Message } @@ -126,15 +100,11 @@ func (m *_OpcuaCloseRequest) GetMessage() ExtensionObject { /////////////////////////////////////////////////////////// // NewOpcuaCloseRequest factory function for _OpcuaCloseRequest -func NewOpcuaCloseRequest(chunk string, secureChannelId int32, secureTokenId int32, sequenceNumber int32, requestId int32, message ExtensionObject) *_OpcuaCloseRequest { +func NewOpcuaCloseRequest(securityHeader SecurityHeader, message Payload, chunk ChunkType) *_OpcuaCloseRequest { _result := &_OpcuaCloseRequest{ - Chunk: chunk, - SecureChannelId: secureChannelId, - SecureTokenId: secureTokenId, - SequenceNumber: sequenceNumber, - RequestId: requestId, - Message: message, - _MessagePDU: NewMessagePDU(), + SecurityHeader: securityHeader, + Message: message, + _MessagePDU: NewMessagePDU(chunk), } _result._MessagePDU._MessagePDUChildRequirements = _result return _result @@ -158,23 +128,8 @@ func (m *_OpcuaCloseRequest) GetTypeName() string { func (m *_OpcuaCloseRequest) GetLengthInBits(ctx context.Context) uint16 { lengthInBits := uint16(m.GetParentLengthInBits(ctx)) - // Simple field (chunk) - lengthInBits += 8 - - // Implicit Field (messageSize) - lengthInBits += 32 - - // Simple field (secureChannelId) - lengthInBits += 32 - - // Simple field (secureTokenId) - lengthInBits += 32 - - // Simple field (sequenceNumber) - lengthInBits += 32 - - // Simple field (requestId) - lengthInBits += 32 + // Simple field (securityHeader) + lengthInBits += m.SecurityHeader.GetLengthInBits(ctx) // Simple field (message) lengthInBits += m.Message.GetLengthInBits(ctx) @@ -201,57 +156,28 @@ func OpcuaCloseRequestParseWithBuffer(ctx context.Context, readBuffer utils.Read currentPos := positionAware.GetPos() _ = currentPos - // Simple Field (chunk) - _chunk, _chunkErr := readBuffer.ReadString("chunk", uint32(8), "UTF-8") - if _chunkErr != nil { - return nil, errors.Wrap(_chunkErr, "Error parsing 'chunk' field of OpcuaCloseRequest") - } - chunk := _chunk - - // Implicit Field (messageSize) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) - messageSize, _messageSizeErr := readBuffer.ReadInt32("messageSize", 32) - _ = messageSize - if _messageSizeErr != nil { - return nil, errors.Wrap(_messageSizeErr, "Error parsing 'messageSize' field of OpcuaCloseRequest") - } - - // Simple Field (secureChannelId) - _secureChannelId, _secureChannelIdErr := readBuffer.ReadInt32("secureChannelId", 32) - if _secureChannelIdErr != nil { - return nil, errors.Wrap(_secureChannelIdErr, "Error parsing 'secureChannelId' field of OpcuaCloseRequest") - } - secureChannelId := _secureChannelId - - // Simple Field (secureTokenId) - _secureTokenId, _secureTokenIdErr := readBuffer.ReadInt32("secureTokenId", 32) - if _secureTokenIdErr != nil { - return nil, errors.Wrap(_secureTokenIdErr, "Error parsing 'secureTokenId' field of OpcuaCloseRequest") + // Simple Field (securityHeader) + if pullErr := readBuffer.PullContext("securityHeader"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for securityHeader") } - secureTokenId := _secureTokenId - - // Simple Field (sequenceNumber) - _sequenceNumber, _sequenceNumberErr := readBuffer.ReadInt32("sequenceNumber", 32) - if _sequenceNumberErr != nil { - return nil, errors.Wrap(_sequenceNumberErr, "Error parsing 'sequenceNumber' field of OpcuaCloseRequest") + _securityHeader, _securityHeaderErr := SecurityHeaderParseWithBuffer(ctx, readBuffer) + if _securityHeaderErr != nil { + return nil, errors.Wrap(_securityHeaderErr, "Error parsing 'securityHeader' field of OpcuaCloseRequest") } - sequenceNumber := _sequenceNumber - - // Simple Field (requestId) - _requestId, _requestIdErr := readBuffer.ReadInt32("requestId", 32) - if _requestIdErr != nil { - return nil, errors.Wrap(_requestIdErr, "Error parsing 'requestId' field of OpcuaCloseRequest") + securityHeader := _securityHeader.(SecurityHeader) + if closeErr := readBuffer.CloseContext("securityHeader"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for securityHeader") } - requestId := _requestId // Simple Field (message) if pullErr := readBuffer.PullContext("message"); pullErr != nil { return nil, errors.Wrap(pullErr, "Error pulling for message") } - _message, _messageErr := ExtensionObjectParseWithBuffer(ctx, readBuffer, bool(bool(false))) + _message, _messageErr := PayloadParseWithBuffer(ctx, readBuffer, bool(bool(true)), uint32(uint32(0))) if _messageErr != nil { return nil, errors.Wrap(_messageErr, "Error parsing 'message' field of OpcuaCloseRequest") } - message := _message.(ExtensionObject) + message := _message.(Payload) if closeErr := readBuffer.CloseContext("message"); closeErr != nil { return nil, errors.Wrap(closeErr, "Error closing for message") } @@ -262,13 +188,9 @@ func OpcuaCloseRequestParseWithBuffer(ctx context.Context, readBuffer utils.Read // Create a partially initialized instance _child := &_OpcuaCloseRequest{ - _MessagePDU: &_MessagePDU{}, - Chunk: chunk, - SecureChannelId: secureChannelId, - SecureTokenId: secureTokenId, - SequenceNumber: sequenceNumber, - RequestId: requestId, - Message: message, + _MessagePDU: &_MessagePDU{}, + SecurityHeader: securityHeader, + Message: message, } _child._MessagePDU._MessagePDUChildRequirements = _child return _child, nil @@ -292,46 +214,16 @@ func (m *_OpcuaCloseRequest) SerializeWithWriteBuffer(ctx context.Context, write return errors.Wrap(pushErr, "Error pushing for OpcuaCloseRequest") } - // Simple Field (chunk) - chunk := string(m.GetChunk()) - _chunkErr := writeBuffer.WriteString("chunk", uint32(8), "UTF-8", (chunk)) - if _chunkErr != nil { - return errors.Wrap(_chunkErr, "Error serializing 'chunk' field") + // Simple Field (securityHeader) + if pushErr := writeBuffer.PushContext("securityHeader"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for securityHeader") } - - // Implicit Field (messageSize) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - messageSize := int32(int32(m.GetLengthInBytes(ctx))) - _messageSizeErr := writeBuffer.WriteInt32("messageSize", 32, int32((messageSize))) - if _messageSizeErr != nil { - return errors.Wrap(_messageSizeErr, "Error serializing 'messageSize' field") + _securityHeaderErr := writeBuffer.WriteSerializable(ctx, m.GetSecurityHeader()) + if popErr := writeBuffer.PopContext("securityHeader"); popErr != nil { + return errors.Wrap(popErr, "Error popping for securityHeader") } - - // Simple Field (secureChannelId) - secureChannelId := int32(m.GetSecureChannelId()) - _secureChannelIdErr := writeBuffer.WriteInt32("secureChannelId", 32, int32((secureChannelId))) - if _secureChannelIdErr != nil { - return errors.Wrap(_secureChannelIdErr, "Error serializing 'secureChannelId' field") - } - - // Simple Field (secureTokenId) - secureTokenId := int32(m.GetSecureTokenId()) - _secureTokenIdErr := writeBuffer.WriteInt32("secureTokenId", 32, int32((secureTokenId))) - if _secureTokenIdErr != nil { - return errors.Wrap(_secureTokenIdErr, "Error serializing 'secureTokenId' field") - } - - // Simple Field (sequenceNumber) - sequenceNumber := int32(m.GetSequenceNumber()) - _sequenceNumberErr := writeBuffer.WriteInt32("sequenceNumber", 32, int32((sequenceNumber))) - if _sequenceNumberErr != nil { - return errors.Wrap(_sequenceNumberErr, "Error serializing 'sequenceNumber' field") - } - - // Simple Field (requestId) - requestId := int32(m.GetRequestId()) - _requestIdErr := writeBuffer.WriteInt32("requestId", 32, int32((requestId))) - if _requestIdErr != nil { - return errors.Wrap(_requestIdErr, "Error serializing 'requestId' field") + if _securityHeaderErr != nil { + return errors.Wrap(_securityHeaderErr, "Error serializing 'securityHeader' field") } // Simple Field (message) diff --git a/plc4go/protocols/opcua/readwrite/model/OpcuaConstants.go b/plc4go/protocols/opcua/readwrite/model/OpcuaConstants.go new file mode 100644 index 00000000000..fb6a22c34fd --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/OpcuaConstants.go @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + "github.com/apache/plc4x/plc4go/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// Constant values. +const OpcuaConstants_PROTOCOLVERSION uint8 = uint8(0) + +// OpcuaConstants is the corresponding interface of OpcuaConstants +type OpcuaConstants interface { + fmt.Stringer + utils.LengthAware + utils.Serializable +} + +// OpcuaConstantsExactly can be used when we want exactly this type and not a type which fulfills OpcuaConstants. +// This is useful for switch cases. +type OpcuaConstantsExactly interface { + OpcuaConstants + isOpcuaConstants() bool +} + +// _OpcuaConstants is the data-structure of this message +type _OpcuaConstants struct { +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for const fields. +/////////////////////// + +func (m *_OpcuaConstants) GetProtocolVersion() uint8 { + return OpcuaConstants_PROTOCOLVERSION +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewOpcuaConstants factory function for _OpcuaConstants +func NewOpcuaConstants() *_OpcuaConstants { + return &_OpcuaConstants{} +} + +// Deprecated: use the interface for direct cast +func CastOpcuaConstants(structType any) OpcuaConstants { + if casted, ok := structType.(OpcuaConstants); ok { + return casted + } + if casted, ok := structType.(*OpcuaConstants); ok { + return *casted + } + return nil +} + +func (m *_OpcuaConstants) GetTypeName() string { + return "OpcuaConstants" +} + +func (m *_OpcuaConstants) GetLengthInBits(ctx context.Context) uint16 { + lengthInBits := uint16(0) + + // Const Field (protocolVersion) + lengthInBits += 8 + + return lengthInBits +} + +func (m *_OpcuaConstants) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func OpcuaConstantsParse(ctx context.Context, theBytes []byte) (OpcuaConstants, error) { + return OpcuaConstantsParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes)) +} + +func OpcuaConstantsParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) (OpcuaConstants, error) { + positionAware := readBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pullErr := readBuffer.PullContext("OpcuaConstants"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for OpcuaConstants") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Const Field (protocolVersion) + protocolVersion, _protocolVersionErr := readBuffer.ReadUint8("protocolVersion", 8) + if _protocolVersionErr != nil { + return nil, errors.Wrap(_protocolVersionErr, "Error parsing 'protocolVersion' field of OpcuaConstants") + } + if protocolVersion != OpcuaConstants_PROTOCOLVERSION { + return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", OpcuaConstants_PROTOCOLVERSION) + " but got " + fmt.Sprintf("%d", protocolVersion)) + } + + if closeErr := readBuffer.CloseContext("OpcuaConstants"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for OpcuaConstants") + } + + // Create the instance + return &_OpcuaConstants{}, nil +} + +func (m *_OpcuaConstants) Serialize() ([]byte, error) { + wb := utils.NewWriteBufferByteBased(utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes(context.Background())))) + if err := m.SerializeWithWriteBuffer(context.Background(), wb); err != nil { + return nil, err + } + return wb.GetBytes(), nil +} + +func (m *_OpcuaConstants) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { + positionAware := writeBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pushErr := writeBuffer.PushContext("OpcuaConstants"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for OpcuaConstants") + } + + // Const Field (protocolVersion) + _protocolVersionErr := writeBuffer.WriteUint8("protocolVersion", 8, uint8(0)) + if _protocolVersionErr != nil { + return errors.Wrap(_protocolVersionErr, "Error serializing 'protocolVersion' field") + } + + if popErr := writeBuffer.PopContext("OpcuaConstants"); popErr != nil { + return errors.Wrap(popErr, "Error popping for OpcuaConstants") + } + return nil +} + +func (m *_OpcuaConstants) isOpcuaConstants() bool { + return true +} + +func (m *_OpcuaConstants) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) + if err := writeBuffer.WriteSerializable(context.Background(), m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/opcua/readwrite/model/OpcuaHelloRequest.go b/plc4go/protocols/opcua/readwrite/model/OpcuaHelloRequest.go index 28e98e0283d..fee7a43d9ac 100644 --- a/plc4go/protocols/opcua/readwrite/model/OpcuaHelloRequest.go +++ b/plc4go/protocols/opcua/readwrite/model/OpcuaHelloRequest.go @@ -35,18 +35,10 @@ type OpcuaHelloRequest interface { utils.LengthAware utils.Serializable MessagePDU - // GetChunk returns Chunk (property field) - GetChunk() string // GetVersion returns Version (property field) - GetVersion() int32 - // GetReceiveBufferSize returns ReceiveBufferSize (property field) - GetReceiveBufferSize() int32 - // GetSendBufferSize returns SendBufferSize (property field) - GetSendBufferSize() int32 - // GetMaxMessageSize returns MaxMessageSize (property field) - GetMaxMessageSize() int32 - // GetMaxChunkCount returns MaxChunkCount (property field) - GetMaxChunkCount() int32 + GetVersion() uint32 + // GetLimits returns Limits (property field) + GetLimits() OpcuaProtocolLimits // GetEndpoint returns Endpoint (property field) GetEndpoint() PascalString } @@ -61,13 +53,9 @@ type OpcuaHelloRequestExactly interface { // _OpcuaHelloRequest is the data-structure of this message type _OpcuaHelloRequest struct { *_MessagePDU - Chunk string - Version int32 - ReceiveBufferSize int32 - SendBufferSize int32 - MaxMessageSize int32 - MaxChunkCount int32 - Endpoint PascalString + Version uint32 + Limits OpcuaProtocolLimits + Endpoint PascalString } /////////////////////////////////////////////////////////// @@ -88,7 +76,9 @@ func (m *_OpcuaHelloRequest) GetResponse() bool { /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -func (m *_OpcuaHelloRequest) InitializeParent(parent MessagePDU) {} +func (m *_OpcuaHelloRequest) InitializeParent(parent MessagePDU, chunk ChunkType) { + m.Chunk = chunk +} func (m *_OpcuaHelloRequest) GetParent() MessagePDU { return m._MessagePDU @@ -99,28 +89,12 @@ func (m *_OpcuaHelloRequest) GetParent() MessagePDU { /////////////////////// Accessors for property fields. /////////////////////// -func (m *_OpcuaHelloRequest) GetChunk() string { - return m.Chunk -} - -func (m *_OpcuaHelloRequest) GetVersion() int32 { +func (m *_OpcuaHelloRequest) GetVersion() uint32 { return m.Version } -func (m *_OpcuaHelloRequest) GetReceiveBufferSize() int32 { - return m.ReceiveBufferSize -} - -func (m *_OpcuaHelloRequest) GetSendBufferSize() int32 { - return m.SendBufferSize -} - -func (m *_OpcuaHelloRequest) GetMaxMessageSize() int32 { - return m.MaxMessageSize -} - -func (m *_OpcuaHelloRequest) GetMaxChunkCount() int32 { - return m.MaxChunkCount +func (m *_OpcuaHelloRequest) GetLimits() OpcuaProtocolLimits { + return m.Limits } func (m *_OpcuaHelloRequest) GetEndpoint() PascalString { @@ -133,16 +107,12 @@ func (m *_OpcuaHelloRequest) GetEndpoint() PascalString { /////////////////////////////////////////////////////////// // NewOpcuaHelloRequest factory function for _OpcuaHelloRequest -func NewOpcuaHelloRequest(chunk string, version int32, receiveBufferSize int32, sendBufferSize int32, maxMessageSize int32, maxChunkCount int32, endpoint PascalString) *_OpcuaHelloRequest { +func NewOpcuaHelloRequest(version uint32, limits OpcuaProtocolLimits, endpoint PascalString, chunk ChunkType) *_OpcuaHelloRequest { _result := &_OpcuaHelloRequest{ - Chunk: chunk, - Version: version, - ReceiveBufferSize: receiveBufferSize, - SendBufferSize: sendBufferSize, - MaxMessageSize: maxMessageSize, - MaxChunkCount: maxChunkCount, - Endpoint: endpoint, - _MessagePDU: NewMessagePDU(), + Version: version, + Limits: limits, + Endpoint: endpoint, + _MessagePDU: NewMessagePDU(chunk), } _result._MessagePDU._MessagePDUChildRequirements = _result return _result @@ -166,26 +136,11 @@ func (m *_OpcuaHelloRequest) GetTypeName() string { func (m *_OpcuaHelloRequest) GetLengthInBits(ctx context.Context) uint16 { lengthInBits := uint16(m.GetParentLengthInBits(ctx)) - // Simple field (chunk) - lengthInBits += 8 - - // Implicit Field (messageSize) - lengthInBits += 32 - // Simple field (version) lengthInBits += 32 - // Simple field (receiveBufferSize) - lengthInBits += 32 - - // Simple field (sendBufferSize) - lengthInBits += 32 - - // Simple field (maxMessageSize) - lengthInBits += 32 - - // Simple field (maxChunkCount) - lengthInBits += 32 + // Simple field (limits) + lengthInBits += m.Limits.GetLengthInBits(ctx) // Simple field (endpoint) lengthInBits += m.Endpoint.GetLengthInBits(ctx) @@ -212,54 +167,25 @@ func OpcuaHelloRequestParseWithBuffer(ctx context.Context, readBuffer utils.Read currentPos := positionAware.GetPos() _ = currentPos - // Simple Field (chunk) - _chunk, _chunkErr := readBuffer.ReadString("chunk", uint32(8), "UTF-8") - if _chunkErr != nil { - return nil, errors.Wrap(_chunkErr, "Error parsing 'chunk' field of OpcuaHelloRequest") - } - chunk := _chunk - - // Implicit Field (messageSize) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) - messageSize, _messageSizeErr := readBuffer.ReadInt32("messageSize", 32) - _ = messageSize - if _messageSizeErr != nil { - return nil, errors.Wrap(_messageSizeErr, "Error parsing 'messageSize' field of OpcuaHelloRequest") - } - // Simple Field (version) - _version, _versionErr := readBuffer.ReadInt32("version", 32) + _version, _versionErr := readBuffer.ReadUint32("version", 32) if _versionErr != nil { return nil, errors.Wrap(_versionErr, "Error parsing 'version' field of OpcuaHelloRequest") } version := _version - // Simple Field (receiveBufferSize) - _receiveBufferSize, _receiveBufferSizeErr := readBuffer.ReadInt32("receiveBufferSize", 32) - if _receiveBufferSizeErr != nil { - return nil, errors.Wrap(_receiveBufferSizeErr, "Error parsing 'receiveBufferSize' field of OpcuaHelloRequest") + // Simple Field (limits) + if pullErr := readBuffer.PullContext("limits"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for limits") } - receiveBufferSize := _receiveBufferSize - - // Simple Field (sendBufferSize) - _sendBufferSize, _sendBufferSizeErr := readBuffer.ReadInt32("sendBufferSize", 32) - if _sendBufferSizeErr != nil { - return nil, errors.Wrap(_sendBufferSizeErr, "Error parsing 'sendBufferSize' field of OpcuaHelloRequest") - } - sendBufferSize := _sendBufferSize - - // Simple Field (maxMessageSize) - _maxMessageSize, _maxMessageSizeErr := readBuffer.ReadInt32("maxMessageSize", 32) - if _maxMessageSizeErr != nil { - return nil, errors.Wrap(_maxMessageSizeErr, "Error parsing 'maxMessageSize' field of OpcuaHelloRequest") + _limits, _limitsErr := OpcuaProtocolLimitsParseWithBuffer(ctx, readBuffer) + if _limitsErr != nil { + return nil, errors.Wrap(_limitsErr, "Error parsing 'limits' field of OpcuaHelloRequest") } - maxMessageSize := _maxMessageSize - - // Simple Field (maxChunkCount) - _maxChunkCount, _maxChunkCountErr := readBuffer.ReadInt32("maxChunkCount", 32) - if _maxChunkCountErr != nil { - return nil, errors.Wrap(_maxChunkCountErr, "Error parsing 'maxChunkCount' field of OpcuaHelloRequest") + limits := _limits.(OpcuaProtocolLimits) + if closeErr := readBuffer.CloseContext("limits"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for limits") } - maxChunkCount := _maxChunkCount // Simple Field (endpoint) if pullErr := readBuffer.PullContext("endpoint"); pullErr != nil { @@ -280,14 +206,10 @@ func OpcuaHelloRequestParseWithBuffer(ctx context.Context, readBuffer utils.Read // Create a partially initialized instance _child := &_OpcuaHelloRequest{ - _MessagePDU: &_MessagePDU{}, - Chunk: chunk, - Version: version, - ReceiveBufferSize: receiveBufferSize, - SendBufferSize: sendBufferSize, - MaxMessageSize: maxMessageSize, - MaxChunkCount: maxChunkCount, - Endpoint: endpoint, + _MessagePDU: &_MessagePDU{}, + Version: version, + Limits: limits, + Endpoint: endpoint, } _child._MessagePDU._MessagePDUChildRequirements = _child return _child, nil @@ -311,53 +233,23 @@ func (m *_OpcuaHelloRequest) SerializeWithWriteBuffer(ctx context.Context, write return errors.Wrap(pushErr, "Error pushing for OpcuaHelloRequest") } - // Simple Field (chunk) - chunk := string(m.GetChunk()) - _chunkErr := writeBuffer.WriteString("chunk", uint32(8), "UTF-8", (chunk)) - if _chunkErr != nil { - return errors.Wrap(_chunkErr, "Error serializing 'chunk' field") - } - - // Implicit Field (messageSize) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - messageSize := int32(int32(m.GetLengthInBytes(ctx))) - _messageSizeErr := writeBuffer.WriteInt32("messageSize", 32, int32((messageSize))) - if _messageSizeErr != nil { - return errors.Wrap(_messageSizeErr, "Error serializing 'messageSize' field") - } - // Simple Field (version) - version := int32(m.GetVersion()) - _versionErr := writeBuffer.WriteInt32("version", 32, int32((version))) + version := uint32(m.GetVersion()) + _versionErr := writeBuffer.WriteUint32("version", 32, uint32((version))) if _versionErr != nil { return errors.Wrap(_versionErr, "Error serializing 'version' field") } - // Simple Field (receiveBufferSize) - receiveBufferSize := int32(m.GetReceiveBufferSize()) - _receiveBufferSizeErr := writeBuffer.WriteInt32("receiveBufferSize", 32, int32((receiveBufferSize))) - if _receiveBufferSizeErr != nil { - return errors.Wrap(_receiveBufferSizeErr, "Error serializing 'receiveBufferSize' field") + // Simple Field (limits) + if pushErr := writeBuffer.PushContext("limits"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for limits") } - - // Simple Field (sendBufferSize) - sendBufferSize := int32(m.GetSendBufferSize()) - _sendBufferSizeErr := writeBuffer.WriteInt32("sendBufferSize", 32, int32((sendBufferSize))) - if _sendBufferSizeErr != nil { - return errors.Wrap(_sendBufferSizeErr, "Error serializing 'sendBufferSize' field") - } - - // Simple Field (maxMessageSize) - maxMessageSize := int32(m.GetMaxMessageSize()) - _maxMessageSizeErr := writeBuffer.WriteInt32("maxMessageSize", 32, int32((maxMessageSize))) - if _maxMessageSizeErr != nil { - return errors.Wrap(_maxMessageSizeErr, "Error serializing 'maxMessageSize' field") + _limitsErr := writeBuffer.WriteSerializable(ctx, m.GetLimits()) + if popErr := writeBuffer.PopContext("limits"); popErr != nil { + return errors.Wrap(popErr, "Error popping for limits") } - - // Simple Field (maxChunkCount) - maxChunkCount := int32(m.GetMaxChunkCount()) - _maxChunkCountErr := writeBuffer.WriteInt32("maxChunkCount", 32, int32((maxChunkCount))) - if _maxChunkCountErr != nil { - return errors.Wrap(_maxChunkCountErr, "Error serializing 'maxChunkCount' field") + if _limitsErr != nil { + return errors.Wrap(_limitsErr, "Error serializing 'limits' field") } // Simple Field (endpoint) diff --git a/plc4go/protocols/opcua/readwrite/model/OpcuaMessageError.go b/plc4go/protocols/opcua/readwrite/model/OpcuaMessageError.go index 49eeb2541a4..065c145ed9a 100644 --- a/plc4go/protocols/opcua/readwrite/model/OpcuaMessageError.go +++ b/plc4go/protocols/opcua/readwrite/model/OpcuaMessageError.go @@ -35,8 +35,6 @@ type OpcuaMessageError interface { utils.LengthAware utils.Serializable MessagePDU - // GetChunk returns Chunk (property field) - GetChunk() string // GetError returns Error (property field) GetError() OpcuaStatusCode // GetReason returns Reason (property field) @@ -53,7 +51,6 @@ type OpcuaMessageErrorExactly interface { // _OpcuaMessageError is the data-structure of this message type _OpcuaMessageError struct { *_MessagePDU - Chunk string Error OpcuaStatusCode Reason PascalString } @@ -76,7 +73,9 @@ func (m *_OpcuaMessageError) GetResponse() bool { /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -func (m *_OpcuaMessageError) InitializeParent(parent MessagePDU) {} +func (m *_OpcuaMessageError) InitializeParent(parent MessagePDU, chunk ChunkType) { + m.Chunk = chunk +} func (m *_OpcuaMessageError) GetParent() MessagePDU { return m._MessagePDU @@ -87,10 +86,6 @@ func (m *_OpcuaMessageError) GetParent() MessagePDU { /////////////////////// Accessors for property fields. /////////////////////// -func (m *_OpcuaMessageError) GetChunk() string { - return m.Chunk -} - func (m *_OpcuaMessageError) GetError() OpcuaStatusCode { return m.Error } @@ -105,12 +100,11 @@ func (m *_OpcuaMessageError) GetReason() PascalString { /////////////////////////////////////////////////////////// // NewOpcuaMessageError factory function for _OpcuaMessageError -func NewOpcuaMessageError(chunk string, error OpcuaStatusCode, reason PascalString) *_OpcuaMessageError { +func NewOpcuaMessageError(error OpcuaStatusCode, reason PascalString, chunk ChunkType) *_OpcuaMessageError { _result := &_OpcuaMessageError{ - Chunk: chunk, Error: error, Reason: reason, - _MessagePDU: NewMessagePDU(), + _MessagePDU: NewMessagePDU(chunk), } _result._MessagePDU._MessagePDUChildRequirements = _result return _result @@ -134,12 +128,6 @@ func (m *_OpcuaMessageError) GetTypeName() string { func (m *_OpcuaMessageError) GetLengthInBits(ctx context.Context) uint16 { lengthInBits := uint16(m.GetParentLengthInBits(ctx)) - // Simple field (chunk) - lengthInBits += 8 - - // Implicit Field (messageSize) - lengthInBits += 32 - // Simple field (error) lengthInBits += 32 @@ -168,20 +156,6 @@ func OpcuaMessageErrorParseWithBuffer(ctx context.Context, readBuffer utils.Read currentPos := positionAware.GetPos() _ = currentPos - // Simple Field (chunk) - _chunk, _chunkErr := readBuffer.ReadString("chunk", uint32(8), "UTF-8") - if _chunkErr != nil { - return nil, errors.Wrap(_chunkErr, "Error parsing 'chunk' field of OpcuaMessageError") - } - chunk := _chunk - - // Implicit Field (messageSize) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) - messageSize, _messageSizeErr := readBuffer.ReadInt32("messageSize", 32) - _ = messageSize - if _messageSizeErr != nil { - return nil, errors.Wrap(_messageSizeErr, "Error parsing 'messageSize' field of OpcuaMessageError") - } - // Simple Field (error) if pullErr := readBuffer.PullContext("error"); pullErr != nil { return nil, errors.Wrap(pullErr, "Error pulling for error") @@ -215,7 +189,6 @@ func OpcuaMessageErrorParseWithBuffer(ctx context.Context, readBuffer utils.Read // Create a partially initialized instance _child := &_OpcuaMessageError{ _MessagePDU: &_MessagePDU{}, - Chunk: chunk, Error: error, Reason: reason, } @@ -241,20 +214,6 @@ func (m *_OpcuaMessageError) SerializeWithWriteBuffer(ctx context.Context, write return errors.Wrap(pushErr, "Error pushing for OpcuaMessageError") } - // Simple Field (chunk) - chunk := string(m.GetChunk()) - _chunkErr := writeBuffer.WriteString("chunk", uint32(8), "UTF-8", (chunk)) - if _chunkErr != nil { - return errors.Wrap(_chunkErr, "Error serializing 'chunk' field") - } - - // Implicit Field (messageSize) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - messageSize := int32(int32(m.GetLengthInBytes(ctx))) - _messageSizeErr := writeBuffer.WriteInt32("messageSize", 32, int32((messageSize))) - if _messageSizeErr != nil { - return errors.Wrap(_messageSizeErr, "Error serializing 'messageSize' field") - } - // Simple Field (error) if pushErr := writeBuffer.PushContext("error"); pushErr != nil { return errors.Wrap(pushErr, "Error pushing for error") diff --git a/plc4go/protocols/opcua/readwrite/model/OpcuaMessageRequest.go b/plc4go/protocols/opcua/readwrite/model/OpcuaMessageRequest.go index 86dfe9ff6d8..9c613a8745d 100644 --- a/plc4go/protocols/opcua/readwrite/model/OpcuaMessageRequest.go +++ b/plc4go/protocols/opcua/readwrite/model/OpcuaMessageRequest.go @@ -35,18 +35,10 @@ type OpcuaMessageRequest interface { utils.LengthAware utils.Serializable MessagePDU - // GetChunk returns Chunk (property field) - GetChunk() string - // GetSecureChannelId returns SecureChannelId (property field) - GetSecureChannelId() int32 - // GetSecureTokenId returns SecureTokenId (property field) - GetSecureTokenId() int32 - // GetSequenceNumber returns SequenceNumber (property field) - GetSequenceNumber() int32 - // GetRequestId returns RequestId (property field) - GetRequestId() int32 + // GetSecurityHeader returns SecurityHeader (property field) + GetSecurityHeader() SecurityHeader // GetMessage returns Message (property field) - GetMessage() []byte + GetMessage() Payload } // OpcuaMessageRequestExactly can be used when we want exactly this type and not a type which fulfills OpcuaMessageRequest. @@ -59,12 +51,11 @@ type OpcuaMessageRequestExactly interface { // _OpcuaMessageRequest is the data-structure of this message type _OpcuaMessageRequest struct { *_MessagePDU - Chunk string - SecureChannelId int32 - SecureTokenId int32 - SequenceNumber int32 - RequestId int32 - Message []byte + SecurityHeader SecurityHeader + Message Payload + + // Arguments. + TotalLength uint32 } /////////////////////////////////////////////////////////// @@ -85,7 +76,9 @@ func (m *_OpcuaMessageRequest) GetResponse() bool { /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -func (m *_OpcuaMessageRequest) InitializeParent(parent MessagePDU) {} +func (m *_OpcuaMessageRequest) InitializeParent(parent MessagePDU, chunk ChunkType) { + m.Chunk = chunk +} func (m *_OpcuaMessageRequest) GetParent() MessagePDU { return m._MessagePDU @@ -96,27 +89,11 @@ func (m *_OpcuaMessageRequest) GetParent() MessagePDU { /////////////////////// Accessors for property fields. /////////////////////// -func (m *_OpcuaMessageRequest) GetChunk() string { - return m.Chunk -} - -func (m *_OpcuaMessageRequest) GetSecureChannelId() int32 { - return m.SecureChannelId -} - -func (m *_OpcuaMessageRequest) GetSecureTokenId() int32 { - return m.SecureTokenId -} - -func (m *_OpcuaMessageRequest) GetSequenceNumber() int32 { - return m.SequenceNumber +func (m *_OpcuaMessageRequest) GetSecurityHeader() SecurityHeader { + return m.SecurityHeader } -func (m *_OpcuaMessageRequest) GetRequestId() int32 { - return m.RequestId -} - -func (m *_OpcuaMessageRequest) GetMessage() []byte { +func (m *_OpcuaMessageRequest) GetMessage() Payload { return m.Message } @@ -126,15 +103,11 @@ func (m *_OpcuaMessageRequest) GetMessage() []byte { /////////////////////////////////////////////////////////// // NewOpcuaMessageRequest factory function for _OpcuaMessageRequest -func NewOpcuaMessageRequest(chunk string, secureChannelId int32, secureTokenId int32, sequenceNumber int32, requestId int32, message []byte) *_OpcuaMessageRequest { +func NewOpcuaMessageRequest(securityHeader SecurityHeader, message Payload, chunk ChunkType, totalLength uint32) *_OpcuaMessageRequest { _result := &_OpcuaMessageRequest{ - Chunk: chunk, - SecureChannelId: secureChannelId, - SecureTokenId: secureTokenId, - SequenceNumber: sequenceNumber, - RequestId: requestId, - Message: message, - _MessagePDU: NewMessagePDU(), + SecurityHeader: securityHeader, + Message: message, + _MessagePDU: NewMessagePDU(chunk), } _result._MessagePDU._MessagePDUChildRequirements = _result return _result @@ -158,28 +131,11 @@ func (m *_OpcuaMessageRequest) GetTypeName() string { func (m *_OpcuaMessageRequest) GetLengthInBits(ctx context.Context) uint16 { lengthInBits := uint16(m.GetParentLengthInBits(ctx)) - // Simple field (chunk) - lengthInBits += 8 - - // Implicit Field (messageSize) - lengthInBits += 32 - - // Simple field (secureChannelId) - lengthInBits += 32 + // Simple field (securityHeader) + lengthInBits += m.SecurityHeader.GetLengthInBits(ctx) - // Simple field (secureTokenId) - lengthInBits += 32 - - // Simple field (sequenceNumber) - lengthInBits += 32 - - // Simple field (requestId) - lengthInBits += 32 - - // Array field - if len(m.Message) > 0 { - lengthInBits += 8 * uint16(len(m.Message)) - } + // Simple field (message) + lengthInBits += m.Message.GetLengthInBits(ctx) return lengthInBits } @@ -188,11 +144,11 @@ func (m *_OpcuaMessageRequest) GetLengthInBytes(ctx context.Context) uint16 { return m.GetLengthInBits(ctx) / 8 } -func OpcuaMessageRequestParse(ctx context.Context, theBytes []byte, response bool) (OpcuaMessageRequest, error) { - return OpcuaMessageRequestParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), response) +func OpcuaMessageRequestParse(ctx context.Context, theBytes []byte, totalLength uint32, response bool) (OpcuaMessageRequest, error) { + return OpcuaMessageRequestParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), totalLength, response) } -func OpcuaMessageRequestParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, response bool) (OpcuaMessageRequest, error) { +func OpcuaMessageRequestParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, totalLength uint32, response bool) (OpcuaMessageRequest, error) { positionAware := readBuffer _ = positionAware log := zerolog.Ctx(ctx) @@ -203,52 +159,30 @@ func OpcuaMessageRequestParseWithBuffer(ctx context.Context, readBuffer utils.Re currentPos := positionAware.GetPos() _ = currentPos - // Simple Field (chunk) - _chunk, _chunkErr := readBuffer.ReadString("chunk", uint32(8), "UTF-8") - if _chunkErr != nil { - return nil, errors.Wrap(_chunkErr, "Error parsing 'chunk' field of OpcuaMessageRequest") + // Simple Field (securityHeader) + if pullErr := readBuffer.PullContext("securityHeader"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for securityHeader") } - chunk := _chunk - - // Implicit Field (messageSize) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) - messageSize, _messageSizeErr := readBuffer.ReadInt32("messageSize", 32) - _ = messageSize - if _messageSizeErr != nil { - return nil, errors.Wrap(_messageSizeErr, "Error parsing 'messageSize' field of OpcuaMessageRequest") - } - - // Simple Field (secureChannelId) - _secureChannelId, _secureChannelIdErr := readBuffer.ReadInt32("secureChannelId", 32) - if _secureChannelIdErr != nil { - return nil, errors.Wrap(_secureChannelIdErr, "Error parsing 'secureChannelId' field of OpcuaMessageRequest") + _securityHeader, _securityHeaderErr := SecurityHeaderParseWithBuffer(ctx, readBuffer) + if _securityHeaderErr != nil { + return nil, errors.Wrap(_securityHeaderErr, "Error parsing 'securityHeader' field of OpcuaMessageRequest") } - secureChannelId := _secureChannelId - - // Simple Field (secureTokenId) - _secureTokenId, _secureTokenIdErr := readBuffer.ReadInt32("secureTokenId", 32) - if _secureTokenIdErr != nil { - return nil, errors.Wrap(_secureTokenIdErr, "Error parsing 'secureTokenId' field of OpcuaMessageRequest") + securityHeader := _securityHeader.(SecurityHeader) + if closeErr := readBuffer.CloseContext("securityHeader"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for securityHeader") } - secureTokenId := _secureTokenId - // Simple Field (sequenceNumber) - _sequenceNumber, _sequenceNumberErr := readBuffer.ReadInt32("sequenceNumber", 32) - if _sequenceNumberErr != nil { - return nil, errors.Wrap(_sequenceNumberErr, "Error parsing 'sequenceNumber' field of OpcuaMessageRequest") + // Simple Field (message) + if pullErr := readBuffer.PullContext("message"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for message") } - sequenceNumber := _sequenceNumber - - // Simple Field (requestId) - _requestId, _requestIdErr := readBuffer.ReadInt32("requestId", 32) - if _requestIdErr != nil { - return nil, errors.Wrap(_requestIdErr, "Error parsing 'requestId' field of OpcuaMessageRequest") + _message, _messageErr := PayloadParseWithBuffer(ctx, readBuffer, bool(bool(false)), uint32(uint32(uint32(totalLength)-uint32(securityHeader.GetLengthInBytes(ctx)))-uint32(uint32(16)))) + if _messageErr != nil { + return nil, errors.Wrap(_messageErr, "Error parsing 'message' field of OpcuaMessageRequest") } - requestId := _requestId - // Byte Array field (message) - numberOfBytesmessage := int(uint16(messageSize) - uint16(uint16(24))) - message, _readArrayErr := readBuffer.ReadByteArray("message", numberOfBytesmessage) - if _readArrayErr != nil { - return nil, errors.Wrap(_readArrayErr, "Error parsing 'message' field of OpcuaMessageRequest") + message := _message.(Payload) + if closeErr := readBuffer.CloseContext("message"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for message") } if closeErr := readBuffer.CloseContext("OpcuaMessageRequest"); closeErr != nil { @@ -257,13 +191,9 @@ func OpcuaMessageRequestParseWithBuffer(ctx context.Context, readBuffer utils.Re // Create a partially initialized instance _child := &_OpcuaMessageRequest{ - _MessagePDU: &_MessagePDU{}, - Chunk: chunk, - SecureChannelId: secureChannelId, - SecureTokenId: secureTokenId, - SequenceNumber: sequenceNumber, - RequestId: requestId, - Message: message, + _MessagePDU: &_MessagePDU{}, + SecurityHeader: securityHeader, + Message: message, } _child._MessagePDU._MessagePDUChildRequirements = _child return _child, nil @@ -287,52 +217,28 @@ func (m *_OpcuaMessageRequest) SerializeWithWriteBuffer(ctx context.Context, wri return errors.Wrap(pushErr, "Error pushing for OpcuaMessageRequest") } - // Simple Field (chunk) - chunk := string(m.GetChunk()) - _chunkErr := writeBuffer.WriteString("chunk", uint32(8), "UTF-8", (chunk)) - if _chunkErr != nil { - return errors.Wrap(_chunkErr, "Error serializing 'chunk' field") + // Simple Field (securityHeader) + if pushErr := writeBuffer.PushContext("securityHeader"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for securityHeader") } - - // Implicit Field (messageSize) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - messageSize := int32(int32(m.GetLengthInBytes(ctx))) - _messageSizeErr := writeBuffer.WriteInt32("messageSize", 32, int32((messageSize))) - if _messageSizeErr != nil { - return errors.Wrap(_messageSizeErr, "Error serializing 'messageSize' field") + _securityHeaderErr := writeBuffer.WriteSerializable(ctx, m.GetSecurityHeader()) + if popErr := writeBuffer.PopContext("securityHeader"); popErr != nil { + return errors.Wrap(popErr, "Error popping for securityHeader") } - - // Simple Field (secureChannelId) - secureChannelId := int32(m.GetSecureChannelId()) - _secureChannelIdErr := writeBuffer.WriteInt32("secureChannelId", 32, int32((secureChannelId))) - if _secureChannelIdErr != nil { - return errors.Wrap(_secureChannelIdErr, "Error serializing 'secureChannelId' field") + if _securityHeaderErr != nil { + return errors.Wrap(_securityHeaderErr, "Error serializing 'securityHeader' field") } - // Simple Field (secureTokenId) - secureTokenId := int32(m.GetSecureTokenId()) - _secureTokenIdErr := writeBuffer.WriteInt32("secureTokenId", 32, int32((secureTokenId))) - if _secureTokenIdErr != nil { - return errors.Wrap(_secureTokenIdErr, "Error serializing 'secureTokenId' field") + // Simple Field (message) + if pushErr := writeBuffer.PushContext("message"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for message") } - - // Simple Field (sequenceNumber) - sequenceNumber := int32(m.GetSequenceNumber()) - _sequenceNumberErr := writeBuffer.WriteInt32("sequenceNumber", 32, int32((sequenceNumber))) - if _sequenceNumberErr != nil { - return errors.Wrap(_sequenceNumberErr, "Error serializing 'sequenceNumber' field") + _messageErr := writeBuffer.WriteSerializable(ctx, m.GetMessage()) + if popErr := writeBuffer.PopContext("message"); popErr != nil { + return errors.Wrap(popErr, "Error popping for message") } - - // Simple Field (requestId) - requestId := int32(m.GetRequestId()) - _requestIdErr := writeBuffer.WriteInt32("requestId", 32, int32((requestId))) - if _requestIdErr != nil { - return errors.Wrap(_requestIdErr, "Error serializing 'requestId' field") - } - - // Array Field (message) - // Byte Array field (message) - if err := writeBuffer.WriteByteArray("message", m.GetMessage()); err != nil { - return errors.Wrap(err, "Error serializing 'message' field") + if _messageErr != nil { + return errors.Wrap(_messageErr, "Error serializing 'message' field") } if popErr := writeBuffer.PopContext("OpcuaMessageRequest"); popErr != nil { @@ -343,6 +249,16 @@ func (m *_OpcuaMessageRequest) SerializeWithWriteBuffer(ctx context.Context, wri return m.SerializeParent(ctx, writeBuffer, m, ser) } +//// +// Arguments Getter + +func (m *_OpcuaMessageRequest) GetTotalLength() uint32 { + return m.TotalLength +} + +// +//// + func (m *_OpcuaMessageRequest) isOpcuaMessageRequest() bool { return true } diff --git a/plc4go/protocols/opcua/readwrite/model/OpcuaMessageResponse.go b/plc4go/protocols/opcua/readwrite/model/OpcuaMessageResponse.go index 5dc106f5111..00007006fb4 100644 --- a/plc4go/protocols/opcua/readwrite/model/OpcuaMessageResponse.go +++ b/plc4go/protocols/opcua/readwrite/model/OpcuaMessageResponse.go @@ -35,18 +35,10 @@ type OpcuaMessageResponse interface { utils.LengthAware utils.Serializable MessagePDU - // GetChunk returns Chunk (property field) - GetChunk() string - // GetSecureChannelId returns SecureChannelId (property field) - GetSecureChannelId() int32 - // GetSecureTokenId returns SecureTokenId (property field) - GetSecureTokenId() int32 - // GetSequenceNumber returns SequenceNumber (property field) - GetSequenceNumber() int32 - // GetRequestId returns RequestId (property field) - GetRequestId() int32 + // GetSecurityHeader returns SecurityHeader (property field) + GetSecurityHeader() SecurityHeader // GetMessage returns Message (property field) - GetMessage() []byte + GetMessage() Payload } // OpcuaMessageResponseExactly can be used when we want exactly this type and not a type which fulfills OpcuaMessageResponse. @@ -59,12 +51,11 @@ type OpcuaMessageResponseExactly interface { // _OpcuaMessageResponse is the data-structure of this message type _OpcuaMessageResponse struct { *_MessagePDU - Chunk string - SecureChannelId int32 - SecureTokenId int32 - SequenceNumber int32 - RequestId int32 - Message []byte + SecurityHeader SecurityHeader + Message Payload + + // Arguments. + TotalLength uint32 } /////////////////////////////////////////////////////////// @@ -85,7 +76,9 @@ func (m *_OpcuaMessageResponse) GetResponse() bool { /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -func (m *_OpcuaMessageResponse) InitializeParent(parent MessagePDU) {} +func (m *_OpcuaMessageResponse) InitializeParent(parent MessagePDU, chunk ChunkType) { + m.Chunk = chunk +} func (m *_OpcuaMessageResponse) GetParent() MessagePDU { return m._MessagePDU @@ -96,27 +89,11 @@ func (m *_OpcuaMessageResponse) GetParent() MessagePDU { /////////////////////// Accessors for property fields. /////////////////////// -func (m *_OpcuaMessageResponse) GetChunk() string { - return m.Chunk -} - -func (m *_OpcuaMessageResponse) GetSecureChannelId() int32 { - return m.SecureChannelId -} - -func (m *_OpcuaMessageResponse) GetSecureTokenId() int32 { - return m.SecureTokenId -} - -func (m *_OpcuaMessageResponse) GetSequenceNumber() int32 { - return m.SequenceNumber +func (m *_OpcuaMessageResponse) GetSecurityHeader() SecurityHeader { + return m.SecurityHeader } -func (m *_OpcuaMessageResponse) GetRequestId() int32 { - return m.RequestId -} - -func (m *_OpcuaMessageResponse) GetMessage() []byte { +func (m *_OpcuaMessageResponse) GetMessage() Payload { return m.Message } @@ -126,15 +103,11 @@ func (m *_OpcuaMessageResponse) GetMessage() []byte { /////////////////////////////////////////////////////////// // NewOpcuaMessageResponse factory function for _OpcuaMessageResponse -func NewOpcuaMessageResponse(chunk string, secureChannelId int32, secureTokenId int32, sequenceNumber int32, requestId int32, message []byte) *_OpcuaMessageResponse { +func NewOpcuaMessageResponse(securityHeader SecurityHeader, message Payload, chunk ChunkType, totalLength uint32) *_OpcuaMessageResponse { _result := &_OpcuaMessageResponse{ - Chunk: chunk, - SecureChannelId: secureChannelId, - SecureTokenId: secureTokenId, - SequenceNumber: sequenceNumber, - RequestId: requestId, - Message: message, - _MessagePDU: NewMessagePDU(), + SecurityHeader: securityHeader, + Message: message, + _MessagePDU: NewMessagePDU(chunk), } _result._MessagePDU._MessagePDUChildRequirements = _result return _result @@ -158,28 +131,11 @@ func (m *_OpcuaMessageResponse) GetTypeName() string { func (m *_OpcuaMessageResponse) GetLengthInBits(ctx context.Context) uint16 { lengthInBits := uint16(m.GetParentLengthInBits(ctx)) - // Simple field (chunk) - lengthInBits += 8 - - // Implicit Field (messageSize) - lengthInBits += 32 - - // Simple field (secureChannelId) - lengthInBits += 32 + // Simple field (securityHeader) + lengthInBits += m.SecurityHeader.GetLengthInBits(ctx) - // Simple field (secureTokenId) - lengthInBits += 32 - - // Simple field (sequenceNumber) - lengthInBits += 32 - - // Simple field (requestId) - lengthInBits += 32 - - // Array field - if len(m.Message) > 0 { - lengthInBits += 8 * uint16(len(m.Message)) - } + // Simple field (message) + lengthInBits += m.Message.GetLengthInBits(ctx) return lengthInBits } @@ -188,11 +144,11 @@ func (m *_OpcuaMessageResponse) GetLengthInBytes(ctx context.Context) uint16 { return m.GetLengthInBits(ctx) / 8 } -func OpcuaMessageResponseParse(ctx context.Context, theBytes []byte, response bool) (OpcuaMessageResponse, error) { - return OpcuaMessageResponseParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), response) +func OpcuaMessageResponseParse(ctx context.Context, theBytes []byte, totalLength uint32, response bool) (OpcuaMessageResponse, error) { + return OpcuaMessageResponseParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), totalLength, response) } -func OpcuaMessageResponseParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, response bool) (OpcuaMessageResponse, error) { +func OpcuaMessageResponseParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, totalLength uint32, response bool) (OpcuaMessageResponse, error) { positionAware := readBuffer _ = positionAware log := zerolog.Ctx(ctx) @@ -203,52 +159,30 @@ func OpcuaMessageResponseParseWithBuffer(ctx context.Context, readBuffer utils.R currentPos := positionAware.GetPos() _ = currentPos - // Simple Field (chunk) - _chunk, _chunkErr := readBuffer.ReadString("chunk", uint32(8), "UTF-8") - if _chunkErr != nil { - return nil, errors.Wrap(_chunkErr, "Error parsing 'chunk' field of OpcuaMessageResponse") + // Simple Field (securityHeader) + if pullErr := readBuffer.PullContext("securityHeader"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for securityHeader") } - chunk := _chunk - - // Implicit Field (messageSize) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) - messageSize, _messageSizeErr := readBuffer.ReadInt32("messageSize", 32) - _ = messageSize - if _messageSizeErr != nil { - return nil, errors.Wrap(_messageSizeErr, "Error parsing 'messageSize' field of OpcuaMessageResponse") - } - - // Simple Field (secureChannelId) - _secureChannelId, _secureChannelIdErr := readBuffer.ReadInt32("secureChannelId", 32) - if _secureChannelIdErr != nil { - return nil, errors.Wrap(_secureChannelIdErr, "Error parsing 'secureChannelId' field of OpcuaMessageResponse") + _securityHeader, _securityHeaderErr := SecurityHeaderParseWithBuffer(ctx, readBuffer) + if _securityHeaderErr != nil { + return nil, errors.Wrap(_securityHeaderErr, "Error parsing 'securityHeader' field of OpcuaMessageResponse") } - secureChannelId := _secureChannelId - - // Simple Field (secureTokenId) - _secureTokenId, _secureTokenIdErr := readBuffer.ReadInt32("secureTokenId", 32) - if _secureTokenIdErr != nil { - return nil, errors.Wrap(_secureTokenIdErr, "Error parsing 'secureTokenId' field of OpcuaMessageResponse") + securityHeader := _securityHeader.(SecurityHeader) + if closeErr := readBuffer.CloseContext("securityHeader"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for securityHeader") } - secureTokenId := _secureTokenId - // Simple Field (sequenceNumber) - _sequenceNumber, _sequenceNumberErr := readBuffer.ReadInt32("sequenceNumber", 32) - if _sequenceNumberErr != nil { - return nil, errors.Wrap(_sequenceNumberErr, "Error parsing 'sequenceNumber' field of OpcuaMessageResponse") + // Simple Field (message) + if pullErr := readBuffer.PullContext("message"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for message") } - sequenceNumber := _sequenceNumber - - // Simple Field (requestId) - _requestId, _requestIdErr := readBuffer.ReadInt32("requestId", 32) - if _requestIdErr != nil { - return nil, errors.Wrap(_requestIdErr, "Error parsing 'requestId' field of OpcuaMessageResponse") + _message, _messageErr := PayloadParseWithBuffer(ctx, readBuffer, bool(bool(false)), uint32(uint32(uint32(totalLength)-uint32(securityHeader.GetLengthInBytes(ctx)))-uint32(uint32(16)))) + if _messageErr != nil { + return nil, errors.Wrap(_messageErr, "Error parsing 'message' field of OpcuaMessageResponse") } - requestId := _requestId - // Byte Array field (message) - numberOfBytesmessage := int(uint16(messageSize) - uint16(uint16(24))) - message, _readArrayErr := readBuffer.ReadByteArray("message", numberOfBytesmessage) - if _readArrayErr != nil { - return nil, errors.Wrap(_readArrayErr, "Error parsing 'message' field of OpcuaMessageResponse") + message := _message.(Payload) + if closeErr := readBuffer.CloseContext("message"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for message") } if closeErr := readBuffer.CloseContext("OpcuaMessageResponse"); closeErr != nil { @@ -257,13 +191,9 @@ func OpcuaMessageResponseParseWithBuffer(ctx context.Context, readBuffer utils.R // Create a partially initialized instance _child := &_OpcuaMessageResponse{ - _MessagePDU: &_MessagePDU{}, - Chunk: chunk, - SecureChannelId: secureChannelId, - SecureTokenId: secureTokenId, - SequenceNumber: sequenceNumber, - RequestId: requestId, - Message: message, + _MessagePDU: &_MessagePDU{}, + SecurityHeader: securityHeader, + Message: message, } _child._MessagePDU._MessagePDUChildRequirements = _child return _child, nil @@ -287,52 +217,28 @@ func (m *_OpcuaMessageResponse) SerializeWithWriteBuffer(ctx context.Context, wr return errors.Wrap(pushErr, "Error pushing for OpcuaMessageResponse") } - // Simple Field (chunk) - chunk := string(m.GetChunk()) - _chunkErr := writeBuffer.WriteString("chunk", uint32(8), "UTF-8", (chunk)) - if _chunkErr != nil { - return errors.Wrap(_chunkErr, "Error serializing 'chunk' field") + // Simple Field (securityHeader) + if pushErr := writeBuffer.PushContext("securityHeader"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for securityHeader") } - - // Implicit Field (messageSize) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - messageSize := int32(int32(m.GetLengthInBytes(ctx))) - _messageSizeErr := writeBuffer.WriteInt32("messageSize", 32, int32((messageSize))) - if _messageSizeErr != nil { - return errors.Wrap(_messageSizeErr, "Error serializing 'messageSize' field") + _securityHeaderErr := writeBuffer.WriteSerializable(ctx, m.GetSecurityHeader()) + if popErr := writeBuffer.PopContext("securityHeader"); popErr != nil { + return errors.Wrap(popErr, "Error popping for securityHeader") } - - // Simple Field (secureChannelId) - secureChannelId := int32(m.GetSecureChannelId()) - _secureChannelIdErr := writeBuffer.WriteInt32("secureChannelId", 32, int32((secureChannelId))) - if _secureChannelIdErr != nil { - return errors.Wrap(_secureChannelIdErr, "Error serializing 'secureChannelId' field") + if _securityHeaderErr != nil { + return errors.Wrap(_securityHeaderErr, "Error serializing 'securityHeader' field") } - // Simple Field (secureTokenId) - secureTokenId := int32(m.GetSecureTokenId()) - _secureTokenIdErr := writeBuffer.WriteInt32("secureTokenId", 32, int32((secureTokenId))) - if _secureTokenIdErr != nil { - return errors.Wrap(_secureTokenIdErr, "Error serializing 'secureTokenId' field") + // Simple Field (message) + if pushErr := writeBuffer.PushContext("message"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for message") } - - // Simple Field (sequenceNumber) - sequenceNumber := int32(m.GetSequenceNumber()) - _sequenceNumberErr := writeBuffer.WriteInt32("sequenceNumber", 32, int32((sequenceNumber))) - if _sequenceNumberErr != nil { - return errors.Wrap(_sequenceNumberErr, "Error serializing 'sequenceNumber' field") + _messageErr := writeBuffer.WriteSerializable(ctx, m.GetMessage()) + if popErr := writeBuffer.PopContext("message"); popErr != nil { + return errors.Wrap(popErr, "Error popping for message") } - - // Simple Field (requestId) - requestId := int32(m.GetRequestId()) - _requestIdErr := writeBuffer.WriteInt32("requestId", 32, int32((requestId))) - if _requestIdErr != nil { - return errors.Wrap(_requestIdErr, "Error serializing 'requestId' field") - } - - // Array Field (message) - // Byte Array field (message) - if err := writeBuffer.WriteByteArray("message", m.GetMessage()); err != nil { - return errors.Wrap(err, "Error serializing 'message' field") + if _messageErr != nil { + return errors.Wrap(_messageErr, "Error serializing 'message' field") } if popErr := writeBuffer.PopContext("OpcuaMessageResponse"); popErr != nil { @@ -343,6 +249,16 @@ func (m *_OpcuaMessageResponse) SerializeWithWriteBuffer(ctx context.Context, wr return m.SerializeParent(ctx, writeBuffer, m, ser) } +//// +// Arguments Getter + +func (m *_OpcuaMessageResponse) GetTotalLength() uint32 { + return m.TotalLength +} + +// +//// + func (m *_OpcuaMessageResponse) isOpcuaMessageResponse() bool { return true } diff --git a/plc4go/protocols/opcua/readwrite/model/OpcuaOpenRequest.go b/plc4go/protocols/opcua/readwrite/model/OpcuaOpenRequest.go index 69d6ad691b9..944980ee23b 100644 --- a/plc4go/protocols/opcua/readwrite/model/OpcuaOpenRequest.go +++ b/plc4go/protocols/opcua/readwrite/model/OpcuaOpenRequest.go @@ -35,22 +35,10 @@ type OpcuaOpenRequest interface { utils.LengthAware utils.Serializable MessagePDU - // GetChunk returns Chunk (property field) - GetChunk() string - // GetSecureChannelId returns SecureChannelId (property field) - GetSecureChannelId() int32 - // GetEndpoint returns Endpoint (property field) - GetEndpoint() PascalString - // GetSenderCertificate returns SenderCertificate (property field) - GetSenderCertificate() PascalByteString - // GetReceiverCertificateThumbprint returns ReceiverCertificateThumbprint (property field) - GetReceiverCertificateThumbprint() PascalByteString - // GetSequenceNumber returns SequenceNumber (property field) - GetSequenceNumber() int32 - // GetRequestId returns RequestId (property field) - GetRequestId() int32 + // GetOpenRequest returns OpenRequest (property field) + GetOpenRequest() OpenChannelMessage // GetMessage returns Message (property field) - GetMessage() []byte + GetMessage() Payload } // OpcuaOpenRequestExactly can be used when we want exactly this type and not a type which fulfills OpcuaOpenRequest. @@ -63,14 +51,11 @@ type OpcuaOpenRequestExactly interface { // _OpcuaOpenRequest is the data-structure of this message type _OpcuaOpenRequest struct { *_MessagePDU - Chunk string - SecureChannelId int32 - Endpoint PascalString - SenderCertificate PascalByteString - ReceiverCertificateThumbprint PascalByteString - SequenceNumber int32 - RequestId int32 - Message []byte + OpenRequest OpenChannelMessage + Message Payload + + // Arguments. + TotalLength uint32 } /////////////////////////////////////////////////////////// @@ -91,7 +76,9 @@ func (m *_OpcuaOpenRequest) GetResponse() bool { /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -func (m *_OpcuaOpenRequest) InitializeParent(parent MessagePDU) {} +func (m *_OpcuaOpenRequest) InitializeParent(parent MessagePDU, chunk ChunkType) { + m.Chunk = chunk +} func (m *_OpcuaOpenRequest) GetParent() MessagePDU { return m._MessagePDU @@ -102,35 +89,11 @@ func (m *_OpcuaOpenRequest) GetParent() MessagePDU { /////////////////////// Accessors for property fields. /////////////////////// -func (m *_OpcuaOpenRequest) GetChunk() string { - return m.Chunk -} - -func (m *_OpcuaOpenRequest) GetSecureChannelId() int32 { - return m.SecureChannelId -} - -func (m *_OpcuaOpenRequest) GetEndpoint() PascalString { - return m.Endpoint -} - -func (m *_OpcuaOpenRequest) GetSenderCertificate() PascalByteString { - return m.SenderCertificate +func (m *_OpcuaOpenRequest) GetOpenRequest() OpenChannelMessage { + return m.OpenRequest } -func (m *_OpcuaOpenRequest) GetReceiverCertificateThumbprint() PascalByteString { - return m.ReceiverCertificateThumbprint -} - -func (m *_OpcuaOpenRequest) GetSequenceNumber() int32 { - return m.SequenceNumber -} - -func (m *_OpcuaOpenRequest) GetRequestId() int32 { - return m.RequestId -} - -func (m *_OpcuaOpenRequest) GetMessage() []byte { +func (m *_OpcuaOpenRequest) GetMessage() Payload { return m.Message } @@ -140,17 +103,11 @@ func (m *_OpcuaOpenRequest) GetMessage() []byte { /////////////////////////////////////////////////////////// // NewOpcuaOpenRequest factory function for _OpcuaOpenRequest -func NewOpcuaOpenRequest(chunk string, secureChannelId int32, endpoint PascalString, senderCertificate PascalByteString, receiverCertificateThumbprint PascalByteString, sequenceNumber int32, requestId int32, message []byte) *_OpcuaOpenRequest { +func NewOpcuaOpenRequest(openRequest OpenChannelMessage, message Payload, chunk ChunkType, totalLength uint32) *_OpcuaOpenRequest { _result := &_OpcuaOpenRequest{ - Chunk: chunk, - SecureChannelId: secureChannelId, - Endpoint: endpoint, - SenderCertificate: senderCertificate, - ReceiverCertificateThumbprint: receiverCertificateThumbprint, - SequenceNumber: sequenceNumber, - RequestId: requestId, - Message: message, - _MessagePDU: NewMessagePDU(), + OpenRequest: openRequest, + Message: message, + _MessagePDU: NewMessagePDU(chunk), } _result._MessagePDU._MessagePDUChildRequirements = _result return _result @@ -174,34 +131,11 @@ func (m *_OpcuaOpenRequest) GetTypeName() string { func (m *_OpcuaOpenRequest) GetLengthInBits(ctx context.Context) uint16 { lengthInBits := uint16(m.GetParentLengthInBits(ctx)) - // Simple field (chunk) - lengthInBits += 8 - - // Implicit Field (messageSize) - lengthInBits += 32 + // Simple field (openRequest) + lengthInBits += m.OpenRequest.GetLengthInBits(ctx) - // Simple field (secureChannelId) - lengthInBits += 32 - - // Simple field (endpoint) - lengthInBits += m.Endpoint.GetLengthInBits(ctx) - - // Simple field (senderCertificate) - lengthInBits += m.SenderCertificate.GetLengthInBits(ctx) - - // Simple field (receiverCertificateThumbprint) - lengthInBits += m.ReceiverCertificateThumbprint.GetLengthInBits(ctx) - - // Simple field (sequenceNumber) - lengthInBits += 32 - - // Simple field (requestId) - lengthInBits += 32 - - // Array field - if len(m.Message) > 0 { - lengthInBits += 8 * uint16(len(m.Message)) - } + // Simple field (message) + lengthInBits += m.Message.GetLengthInBits(ctx) return lengthInBits } @@ -210,11 +144,11 @@ func (m *_OpcuaOpenRequest) GetLengthInBytes(ctx context.Context) uint16 { return m.GetLengthInBits(ctx) / 8 } -func OpcuaOpenRequestParse(ctx context.Context, theBytes []byte, response bool) (OpcuaOpenRequest, error) { - return OpcuaOpenRequestParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), response) +func OpcuaOpenRequestParse(ctx context.Context, theBytes []byte, totalLength uint32, response bool) (OpcuaOpenRequest, error) { + return OpcuaOpenRequestParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), totalLength, response) } -func OpcuaOpenRequestParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, response bool) (OpcuaOpenRequest, error) { +func OpcuaOpenRequestParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, totalLength uint32, response bool) (OpcuaOpenRequest, error) { positionAware := readBuffer _ = positionAware log := zerolog.Ctx(ctx) @@ -225,84 +159,30 @@ func OpcuaOpenRequestParseWithBuffer(ctx context.Context, readBuffer utils.ReadB currentPos := positionAware.GetPos() _ = currentPos - // Simple Field (chunk) - _chunk, _chunkErr := readBuffer.ReadString("chunk", uint32(8), "UTF-8") - if _chunkErr != nil { - return nil, errors.Wrap(_chunkErr, "Error parsing 'chunk' field of OpcuaOpenRequest") + // Simple Field (openRequest) + if pullErr := readBuffer.PullContext("openRequest"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for openRequest") } - chunk := _chunk - - // Implicit Field (messageSize) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) - messageSize, _messageSizeErr := readBuffer.ReadInt32("messageSize", 32) - _ = messageSize - if _messageSizeErr != nil { - return nil, errors.Wrap(_messageSizeErr, "Error parsing 'messageSize' field of OpcuaOpenRequest") + _openRequest, _openRequestErr := OpenChannelMessageParseWithBuffer(ctx, readBuffer, bool(response)) + if _openRequestErr != nil { + return nil, errors.Wrap(_openRequestErr, "Error parsing 'openRequest' field of OpcuaOpenRequest") } - - // Simple Field (secureChannelId) - _secureChannelId, _secureChannelIdErr := readBuffer.ReadInt32("secureChannelId", 32) - if _secureChannelIdErr != nil { - return nil, errors.Wrap(_secureChannelIdErr, "Error parsing 'secureChannelId' field of OpcuaOpenRequest") + openRequest := _openRequest.(OpenChannelMessage) + if closeErr := readBuffer.CloseContext("openRequest"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for openRequest") } - secureChannelId := _secureChannelId - // Simple Field (endpoint) - if pullErr := readBuffer.PullContext("endpoint"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for endpoint") + // Simple Field (message) + if pullErr := readBuffer.PullContext("message"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for message") } - _endpoint, _endpointErr := PascalStringParseWithBuffer(ctx, readBuffer) - if _endpointErr != nil { - return nil, errors.Wrap(_endpointErr, "Error parsing 'endpoint' field of OpcuaOpenRequest") + _message, _messageErr := PayloadParseWithBuffer(ctx, readBuffer, bool(bool(false)), uint32(uint32(uint32(totalLength)-uint32(openRequest.GetLengthInBytes(ctx)))-uint32(uint32(16)))) + if _messageErr != nil { + return nil, errors.Wrap(_messageErr, "Error parsing 'message' field of OpcuaOpenRequest") } - endpoint := _endpoint.(PascalString) - if closeErr := readBuffer.CloseContext("endpoint"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for endpoint") - } - - // Simple Field (senderCertificate) - if pullErr := readBuffer.PullContext("senderCertificate"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for senderCertificate") - } - _senderCertificate, _senderCertificateErr := PascalByteStringParseWithBuffer(ctx, readBuffer) - if _senderCertificateErr != nil { - return nil, errors.Wrap(_senderCertificateErr, "Error parsing 'senderCertificate' field of OpcuaOpenRequest") - } - senderCertificate := _senderCertificate.(PascalByteString) - if closeErr := readBuffer.CloseContext("senderCertificate"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for senderCertificate") - } - - // Simple Field (receiverCertificateThumbprint) - if pullErr := readBuffer.PullContext("receiverCertificateThumbprint"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for receiverCertificateThumbprint") - } - _receiverCertificateThumbprint, _receiverCertificateThumbprintErr := PascalByteStringParseWithBuffer(ctx, readBuffer) - if _receiverCertificateThumbprintErr != nil { - return nil, errors.Wrap(_receiverCertificateThumbprintErr, "Error parsing 'receiverCertificateThumbprint' field of OpcuaOpenRequest") - } - receiverCertificateThumbprint := _receiverCertificateThumbprint.(PascalByteString) - if closeErr := readBuffer.CloseContext("receiverCertificateThumbprint"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for receiverCertificateThumbprint") - } - - // Simple Field (sequenceNumber) - _sequenceNumber, _sequenceNumberErr := readBuffer.ReadInt32("sequenceNumber", 32) - if _sequenceNumberErr != nil { - return nil, errors.Wrap(_sequenceNumberErr, "Error parsing 'sequenceNumber' field of OpcuaOpenRequest") - } - sequenceNumber := _sequenceNumber - - // Simple Field (requestId) - _requestId, _requestIdErr := readBuffer.ReadInt32("requestId", 32) - if _requestIdErr != nil { - return nil, errors.Wrap(_requestIdErr, "Error parsing 'requestId' field of OpcuaOpenRequest") - } - requestId := _requestId - // Byte Array field (message) - numberOfBytesmessage := int(uint16(uint16(uint16(uint16(messageSize)-uint16((utils.InlineIf(bool((endpoint.GetStringLength()) == (-(1))), func() any { return uint16(uint16(0)) }, func() any { return uint16(endpoint.GetStringLength()) }).(uint16))))-uint16((utils.InlineIf(bool((senderCertificate.GetStringLength()) == (-(1))), func() any { return uint16(uint16(0)) }, func() any { return uint16(senderCertificate.GetStringLength()) }).(uint16))))-uint16((utils.InlineIf(bool((receiverCertificateThumbprint.GetStringLength()) == (-(1))), func() any { return uint16(uint16(0)) }, func() any { return uint16(receiverCertificateThumbprint.GetStringLength()) }).(uint16)))) - uint16(uint16(32))) - message, _readArrayErr := readBuffer.ReadByteArray("message", numberOfBytesmessage) - if _readArrayErr != nil { - return nil, errors.Wrap(_readArrayErr, "Error parsing 'message' field of OpcuaOpenRequest") + message := _message.(Payload) + if closeErr := readBuffer.CloseContext("message"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for message") } if closeErr := readBuffer.CloseContext("OpcuaOpenRequest"); closeErr != nil { @@ -311,15 +191,9 @@ func OpcuaOpenRequestParseWithBuffer(ctx context.Context, readBuffer utils.ReadB // Create a partially initialized instance _child := &_OpcuaOpenRequest{ - _MessagePDU: &_MessagePDU{}, - Chunk: chunk, - SecureChannelId: secureChannelId, - Endpoint: endpoint, - SenderCertificate: senderCertificate, - ReceiverCertificateThumbprint: receiverCertificateThumbprint, - SequenceNumber: sequenceNumber, - RequestId: requestId, - Message: message, + _MessagePDU: &_MessagePDU{}, + OpenRequest: openRequest, + Message: message, } _child._MessagePDU._MessagePDUChildRequirements = _child return _child, nil @@ -343,81 +217,28 @@ func (m *_OpcuaOpenRequest) SerializeWithWriteBuffer(ctx context.Context, writeB return errors.Wrap(pushErr, "Error pushing for OpcuaOpenRequest") } - // Simple Field (chunk) - chunk := string(m.GetChunk()) - _chunkErr := writeBuffer.WriteString("chunk", uint32(8), "UTF-8", (chunk)) - if _chunkErr != nil { - return errors.Wrap(_chunkErr, "Error serializing 'chunk' field") - } - - // Implicit Field (messageSize) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - messageSize := int32(int32(m.GetLengthInBytes(ctx))) - _messageSizeErr := writeBuffer.WriteInt32("messageSize", 32, int32((messageSize))) - if _messageSizeErr != nil { - return errors.Wrap(_messageSizeErr, "Error serializing 'messageSize' field") - } - - // Simple Field (secureChannelId) - secureChannelId := int32(m.GetSecureChannelId()) - _secureChannelIdErr := writeBuffer.WriteInt32("secureChannelId", 32, int32((secureChannelId))) - if _secureChannelIdErr != nil { - return errors.Wrap(_secureChannelIdErr, "Error serializing 'secureChannelId' field") - } - - // Simple Field (endpoint) - if pushErr := writeBuffer.PushContext("endpoint"); pushErr != nil { - return errors.Wrap(pushErr, "Error pushing for endpoint") + // Simple Field (openRequest) + if pushErr := writeBuffer.PushContext("openRequest"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for openRequest") } - _endpointErr := writeBuffer.WriteSerializable(ctx, m.GetEndpoint()) - if popErr := writeBuffer.PopContext("endpoint"); popErr != nil { - return errors.Wrap(popErr, "Error popping for endpoint") + _openRequestErr := writeBuffer.WriteSerializable(ctx, m.GetOpenRequest()) + if popErr := writeBuffer.PopContext("openRequest"); popErr != nil { + return errors.Wrap(popErr, "Error popping for openRequest") } - if _endpointErr != nil { - return errors.Wrap(_endpointErr, "Error serializing 'endpoint' field") + if _openRequestErr != nil { + return errors.Wrap(_openRequestErr, "Error serializing 'openRequest' field") } - // Simple Field (senderCertificate) - if pushErr := writeBuffer.PushContext("senderCertificate"); pushErr != nil { - return errors.Wrap(pushErr, "Error pushing for senderCertificate") + // Simple Field (message) + if pushErr := writeBuffer.PushContext("message"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for message") } - _senderCertificateErr := writeBuffer.WriteSerializable(ctx, m.GetSenderCertificate()) - if popErr := writeBuffer.PopContext("senderCertificate"); popErr != nil { - return errors.Wrap(popErr, "Error popping for senderCertificate") + _messageErr := writeBuffer.WriteSerializable(ctx, m.GetMessage()) + if popErr := writeBuffer.PopContext("message"); popErr != nil { + return errors.Wrap(popErr, "Error popping for message") } - if _senderCertificateErr != nil { - return errors.Wrap(_senderCertificateErr, "Error serializing 'senderCertificate' field") - } - - // Simple Field (receiverCertificateThumbprint) - if pushErr := writeBuffer.PushContext("receiverCertificateThumbprint"); pushErr != nil { - return errors.Wrap(pushErr, "Error pushing for receiverCertificateThumbprint") - } - _receiverCertificateThumbprintErr := writeBuffer.WriteSerializable(ctx, m.GetReceiverCertificateThumbprint()) - if popErr := writeBuffer.PopContext("receiverCertificateThumbprint"); popErr != nil { - return errors.Wrap(popErr, "Error popping for receiverCertificateThumbprint") - } - if _receiverCertificateThumbprintErr != nil { - return errors.Wrap(_receiverCertificateThumbprintErr, "Error serializing 'receiverCertificateThumbprint' field") - } - - // Simple Field (sequenceNumber) - sequenceNumber := int32(m.GetSequenceNumber()) - _sequenceNumberErr := writeBuffer.WriteInt32("sequenceNumber", 32, int32((sequenceNumber))) - if _sequenceNumberErr != nil { - return errors.Wrap(_sequenceNumberErr, "Error serializing 'sequenceNumber' field") - } - - // Simple Field (requestId) - requestId := int32(m.GetRequestId()) - _requestIdErr := writeBuffer.WriteInt32("requestId", 32, int32((requestId))) - if _requestIdErr != nil { - return errors.Wrap(_requestIdErr, "Error serializing 'requestId' field") - } - - // Array Field (message) - // Byte Array field (message) - if err := writeBuffer.WriteByteArray("message", m.GetMessage()); err != nil { - return errors.Wrap(err, "Error serializing 'message' field") + if _messageErr != nil { + return errors.Wrap(_messageErr, "Error serializing 'message' field") } if popErr := writeBuffer.PopContext("OpcuaOpenRequest"); popErr != nil { @@ -428,6 +249,16 @@ func (m *_OpcuaOpenRequest) SerializeWithWriteBuffer(ctx context.Context, writeB return m.SerializeParent(ctx, writeBuffer, m, ser) } +//// +// Arguments Getter + +func (m *_OpcuaOpenRequest) GetTotalLength() uint32 { + return m.TotalLength +} + +// +//// + func (m *_OpcuaOpenRequest) isOpcuaOpenRequest() bool { return true } diff --git a/plc4go/protocols/opcua/readwrite/model/OpcuaOpenResponse.go b/plc4go/protocols/opcua/readwrite/model/OpcuaOpenResponse.go index 67245eb9464..ea8a70b270f 100644 --- a/plc4go/protocols/opcua/readwrite/model/OpcuaOpenResponse.go +++ b/plc4go/protocols/opcua/readwrite/model/OpcuaOpenResponse.go @@ -35,22 +35,10 @@ type OpcuaOpenResponse interface { utils.LengthAware utils.Serializable MessagePDU - // GetChunk returns Chunk (property field) - GetChunk() string - // GetSecureChannelId returns SecureChannelId (property field) - GetSecureChannelId() int32 - // GetSecurityPolicyUri returns SecurityPolicyUri (property field) - GetSecurityPolicyUri() PascalString - // GetSenderCertificate returns SenderCertificate (property field) - GetSenderCertificate() PascalByteString - // GetReceiverCertificateThumbprint returns ReceiverCertificateThumbprint (property field) - GetReceiverCertificateThumbprint() PascalByteString - // GetSequenceNumber returns SequenceNumber (property field) - GetSequenceNumber() int32 - // GetRequestId returns RequestId (property field) - GetRequestId() int32 + // GetOpenResponse returns OpenResponse (property field) + GetOpenResponse() OpenChannelMessage // GetMessage returns Message (property field) - GetMessage() []byte + GetMessage() Payload } // OpcuaOpenResponseExactly can be used when we want exactly this type and not a type which fulfills OpcuaOpenResponse. @@ -63,14 +51,11 @@ type OpcuaOpenResponseExactly interface { // _OpcuaOpenResponse is the data-structure of this message type _OpcuaOpenResponse struct { *_MessagePDU - Chunk string - SecureChannelId int32 - SecurityPolicyUri PascalString - SenderCertificate PascalByteString - ReceiverCertificateThumbprint PascalByteString - SequenceNumber int32 - RequestId int32 - Message []byte + OpenResponse OpenChannelMessage + Message Payload + + // Arguments. + TotalLength uint32 } /////////////////////////////////////////////////////////// @@ -91,7 +76,9 @@ func (m *_OpcuaOpenResponse) GetResponse() bool { /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -func (m *_OpcuaOpenResponse) InitializeParent(parent MessagePDU) {} +func (m *_OpcuaOpenResponse) InitializeParent(parent MessagePDU, chunk ChunkType) { + m.Chunk = chunk +} func (m *_OpcuaOpenResponse) GetParent() MessagePDU { return m._MessagePDU @@ -102,35 +89,11 @@ func (m *_OpcuaOpenResponse) GetParent() MessagePDU { /////////////////////// Accessors for property fields. /////////////////////// -func (m *_OpcuaOpenResponse) GetChunk() string { - return m.Chunk -} - -func (m *_OpcuaOpenResponse) GetSecureChannelId() int32 { - return m.SecureChannelId -} - -func (m *_OpcuaOpenResponse) GetSecurityPolicyUri() PascalString { - return m.SecurityPolicyUri -} - -func (m *_OpcuaOpenResponse) GetSenderCertificate() PascalByteString { - return m.SenderCertificate +func (m *_OpcuaOpenResponse) GetOpenResponse() OpenChannelMessage { + return m.OpenResponse } -func (m *_OpcuaOpenResponse) GetReceiverCertificateThumbprint() PascalByteString { - return m.ReceiverCertificateThumbprint -} - -func (m *_OpcuaOpenResponse) GetSequenceNumber() int32 { - return m.SequenceNumber -} - -func (m *_OpcuaOpenResponse) GetRequestId() int32 { - return m.RequestId -} - -func (m *_OpcuaOpenResponse) GetMessage() []byte { +func (m *_OpcuaOpenResponse) GetMessage() Payload { return m.Message } @@ -140,17 +103,11 @@ func (m *_OpcuaOpenResponse) GetMessage() []byte { /////////////////////////////////////////////////////////// // NewOpcuaOpenResponse factory function for _OpcuaOpenResponse -func NewOpcuaOpenResponse(chunk string, secureChannelId int32, securityPolicyUri PascalString, senderCertificate PascalByteString, receiverCertificateThumbprint PascalByteString, sequenceNumber int32, requestId int32, message []byte) *_OpcuaOpenResponse { +func NewOpcuaOpenResponse(openResponse OpenChannelMessage, message Payload, chunk ChunkType, totalLength uint32) *_OpcuaOpenResponse { _result := &_OpcuaOpenResponse{ - Chunk: chunk, - SecureChannelId: secureChannelId, - SecurityPolicyUri: securityPolicyUri, - SenderCertificate: senderCertificate, - ReceiverCertificateThumbprint: receiverCertificateThumbprint, - SequenceNumber: sequenceNumber, - RequestId: requestId, - Message: message, - _MessagePDU: NewMessagePDU(), + OpenResponse: openResponse, + Message: message, + _MessagePDU: NewMessagePDU(chunk), } _result._MessagePDU._MessagePDUChildRequirements = _result return _result @@ -174,34 +131,11 @@ func (m *_OpcuaOpenResponse) GetTypeName() string { func (m *_OpcuaOpenResponse) GetLengthInBits(ctx context.Context) uint16 { lengthInBits := uint16(m.GetParentLengthInBits(ctx)) - // Simple field (chunk) - lengthInBits += 8 - - // Implicit Field (messageSize) - lengthInBits += 32 + // Simple field (openResponse) + lengthInBits += m.OpenResponse.GetLengthInBits(ctx) - // Simple field (secureChannelId) - lengthInBits += 32 - - // Simple field (securityPolicyUri) - lengthInBits += m.SecurityPolicyUri.GetLengthInBits(ctx) - - // Simple field (senderCertificate) - lengthInBits += m.SenderCertificate.GetLengthInBits(ctx) - - // Simple field (receiverCertificateThumbprint) - lengthInBits += m.ReceiverCertificateThumbprint.GetLengthInBits(ctx) - - // Simple field (sequenceNumber) - lengthInBits += 32 - - // Simple field (requestId) - lengthInBits += 32 - - // Array field - if len(m.Message) > 0 { - lengthInBits += 8 * uint16(len(m.Message)) - } + // Simple field (message) + lengthInBits += m.Message.GetLengthInBits(ctx) return lengthInBits } @@ -210,11 +144,11 @@ func (m *_OpcuaOpenResponse) GetLengthInBytes(ctx context.Context) uint16 { return m.GetLengthInBits(ctx) / 8 } -func OpcuaOpenResponseParse(ctx context.Context, theBytes []byte, response bool) (OpcuaOpenResponse, error) { - return OpcuaOpenResponseParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), response) +func OpcuaOpenResponseParse(ctx context.Context, theBytes []byte, totalLength uint32, response bool) (OpcuaOpenResponse, error) { + return OpcuaOpenResponseParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), totalLength, response) } -func OpcuaOpenResponseParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, response bool) (OpcuaOpenResponse, error) { +func OpcuaOpenResponseParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, totalLength uint32, response bool) (OpcuaOpenResponse, error) { positionAware := readBuffer _ = positionAware log := zerolog.Ctx(ctx) @@ -225,84 +159,30 @@ func OpcuaOpenResponseParseWithBuffer(ctx context.Context, readBuffer utils.Read currentPos := positionAware.GetPos() _ = currentPos - // Simple Field (chunk) - _chunk, _chunkErr := readBuffer.ReadString("chunk", uint32(8), "UTF-8") - if _chunkErr != nil { - return nil, errors.Wrap(_chunkErr, "Error parsing 'chunk' field of OpcuaOpenResponse") + // Simple Field (openResponse) + if pullErr := readBuffer.PullContext("openResponse"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for openResponse") } - chunk := _chunk - - // Implicit Field (messageSize) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) - messageSize, _messageSizeErr := readBuffer.ReadInt32("messageSize", 32) - _ = messageSize - if _messageSizeErr != nil { - return nil, errors.Wrap(_messageSizeErr, "Error parsing 'messageSize' field of OpcuaOpenResponse") + _openResponse, _openResponseErr := OpenChannelMessageParseWithBuffer(ctx, readBuffer, bool(response)) + if _openResponseErr != nil { + return nil, errors.Wrap(_openResponseErr, "Error parsing 'openResponse' field of OpcuaOpenResponse") } - - // Simple Field (secureChannelId) - _secureChannelId, _secureChannelIdErr := readBuffer.ReadInt32("secureChannelId", 32) - if _secureChannelIdErr != nil { - return nil, errors.Wrap(_secureChannelIdErr, "Error parsing 'secureChannelId' field of OpcuaOpenResponse") + openResponse := _openResponse.(OpenChannelMessage) + if closeErr := readBuffer.CloseContext("openResponse"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for openResponse") } - secureChannelId := _secureChannelId - // Simple Field (securityPolicyUri) - if pullErr := readBuffer.PullContext("securityPolicyUri"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for securityPolicyUri") + // Simple Field (message) + if pullErr := readBuffer.PullContext("message"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for message") } - _securityPolicyUri, _securityPolicyUriErr := PascalStringParseWithBuffer(ctx, readBuffer) - if _securityPolicyUriErr != nil { - return nil, errors.Wrap(_securityPolicyUriErr, "Error parsing 'securityPolicyUri' field of OpcuaOpenResponse") + _message, _messageErr := PayloadParseWithBuffer(ctx, readBuffer, bool(bool(false)), uint32(uint32(uint32(totalLength)-uint32(openResponse.GetLengthInBytes(ctx)))-uint32(uint32(16)))) + if _messageErr != nil { + return nil, errors.Wrap(_messageErr, "Error parsing 'message' field of OpcuaOpenResponse") } - securityPolicyUri := _securityPolicyUri.(PascalString) - if closeErr := readBuffer.CloseContext("securityPolicyUri"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for securityPolicyUri") - } - - // Simple Field (senderCertificate) - if pullErr := readBuffer.PullContext("senderCertificate"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for senderCertificate") - } - _senderCertificate, _senderCertificateErr := PascalByteStringParseWithBuffer(ctx, readBuffer) - if _senderCertificateErr != nil { - return nil, errors.Wrap(_senderCertificateErr, "Error parsing 'senderCertificate' field of OpcuaOpenResponse") - } - senderCertificate := _senderCertificate.(PascalByteString) - if closeErr := readBuffer.CloseContext("senderCertificate"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for senderCertificate") - } - - // Simple Field (receiverCertificateThumbprint) - if pullErr := readBuffer.PullContext("receiverCertificateThumbprint"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for receiverCertificateThumbprint") - } - _receiverCertificateThumbprint, _receiverCertificateThumbprintErr := PascalByteStringParseWithBuffer(ctx, readBuffer) - if _receiverCertificateThumbprintErr != nil { - return nil, errors.Wrap(_receiverCertificateThumbprintErr, "Error parsing 'receiverCertificateThumbprint' field of OpcuaOpenResponse") - } - receiverCertificateThumbprint := _receiverCertificateThumbprint.(PascalByteString) - if closeErr := readBuffer.CloseContext("receiverCertificateThumbprint"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for receiverCertificateThumbprint") - } - - // Simple Field (sequenceNumber) - _sequenceNumber, _sequenceNumberErr := readBuffer.ReadInt32("sequenceNumber", 32) - if _sequenceNumberErr != nil { - return nil, errors.Wrap(_sequenceNumberErr, "Error parsing 'sequenceNumber' field of OpcuaOpenResponse") - } - sequenceNumber := _sequenceNumber - - // Simple Field (requestId) - _requestId, _requestIdErr := readBuffer.ReadInt32("requestId", 32) - if _requestIdErr != nil { - return nil, errors.Wrap(_requestIdErr, "Error parsing 'requestId' field of OpcuaOpenResponse") - } - requestId := _requestId - // Byte Array field (message) - numberOfBytesmessage := int(uint16(uint16(uint16(uint16(messageSize)-uint16((utils.InlineIf(bool((securityPolicyUri.GetStringLength()) == (-(1))), func() any { return uint16(uint16(0)) }, func() any { return uint16(securityPolicyUri.GetStringLength()) }).(uint16))))-uint16((utils.InlineIf(bool((senderCertificate.GetStringLength()) == (-(1))), func() any { return uint16(uint16(0)) }, func() any { return uint16(senderCertificate.GetStringLength()) }).(uint16))))-uint16((utils.InlineIf(bool((receiverCertificateThumbprint.GetStringLength()) == (-(1))), func() any { return uint16(uint16(0)) }, func() any { return uint16(receiverCertificateThumbprint.GetStringLength()) }).(uint16)))) - uint16(uint16(32))) - message, _readArrayErr := readBuffer.ReadByteArray("message", numberOfBytesmessage) - if _readArrayErr != nil { - return nil, errors.Wrap(_readArrayErr, "Error parsing 'message' field of OpcuaOpenResponse") + message := _message.(Payload) + if closeErr := readBuffer.CloseContext("message"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for message") } if closeErr := readBuffer.CloseContext("OpcuaOpenResponse"); closeErr != nil { @@ -311,15 +191,9 @@ func OpcuaOpenResponseParseWithBuffer(ctx context.Context, readBuffer utils.Read // Create a partially initialized instance _child := &_OpcuaOpenResponse{ - _MessagePDU: &_MessagePDU{}, - Chunk: chunk, - SecureChannelId: secureChannelId, - SecurityPolicyUri: securityPolicyUri, - SenderCertificate: senderCertificate, - ReceiverCertificateThumbprint: receiverCertificateThumbprint, - SequenceNumber: sequenceNumber, - RequestId: requestId, - Message: message, + _MessagePDU: &_MessagePDU{}, + OpenResponse: openResponse, + Message: message, } _child._MessagePDU._MessagePDUChildRequirements = _child return _child, nil @@ -343,81 +217,28 @@ func (m *_OpcuaOpenResponse) SerializeWithWriteBuffer(ctx context.Context, write return errors.Wrap(pushErr, "Error pushing for OpcuaOpenResponse") } - // Simple Field (chunk) - chunk := string(m.GetChunk()) - _chunkErr := writeBuffer.WriteString("chunk", uint32(8), "UTF-8", (chunk)) - if _chunkErr != nil { - return errors.Wrap(_chunkErr, "Error serializing 'chunk' field") - } - - // Implicit Field (messageSize) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - messageSize := int32(int32(m.GetLengthInBytes(ctx))) - _messageSizeErr := writeBuffer.WriteInt32("messageSize", 32, int32((messageSize))) - if _messageSizeErr != nil { - return errors.Wrap(_messageSizeErr, "Error serializing 'messageSize' field") - } - - // Simple Field (secureChannelId) - secureChannelId := int32(m.GetSecureChannelId()) - _secureChannelIdErr := writeBuffer.WriteInt32("secureChannelId", 32, int32((secureChannelId))) - if _secureChannelIdErr != nil { - return errors.Wrap(_secureChannelIdErr, "Error serializing 'secureChannelId' field") - } - - // Simple Field (securityPolicyUri) - if pushErr := writeBuffer.PushContext("securityPolicyUri"); pushErr != nil { - return errors.Wrap(pushErr, "Error pushing for securityPolicyUri") + // Simple Field (openResponse) + if pushErr := writeBuffer.PushContext("openResponse"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for openResponse") } - _securityPolicyUriErr := writeBuffer.WriteSerializable(ctx, m.GetSecurityPolicyUri()) - if popErr := writeBuffer.PopContext("securityPolicyUri"); popErr != nil { - return errors.Wrap(popErr, "Error popping for securityPolicyUri") + _openResponseErr := writeBuffer.WriteSerializable(ctx, m.GetOpenResponse()) + if popErr := writeBuffer.PopContext("openResponse"); popErr != nil { + return errors.Wrap(popErr, "Error popping for openResponse") } - if _securityPolicyUriErr != nil { - return errors.Wrap(_securityPolicyUriErr, "Error serializing 'securityPolicyUri' field") + if _openResponseErr != nil { + return errors.Wrap(_openResponseErr, "Error serializing 'openResponse' field") } - // Simple Field (senderCertificate) - if pushErr := writeBuffer.PushContext("senderCertificate"); pushErr != nil { - return errors.Wrap(pushErr, "Error pushing for senderCertificate") + // Simple Field (message) + if pushErr := writeBuffer.PushContext("message"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for message") } - _senderCertificateErr := writeBuffer.WriteSerializable(ctx, m.GetSenderCertificate()) - if popErr := writeBuffer.PopContext("senderCertificate"); popErr != nil { - return errors.Wrap(popErr, "Error popping for senderCertificate") + _messageErr := writeBuffer.WriteSerializable(ctx, m.GetMessage()) + if popErr := writeBuffer.PopContext("message"); popErr != nil { + return errors.Wrap(popErr, "Error popping for message") } - if _senderCertificateErr != nil { - return errors.Wrap(_senderCertificateErr, "Error serializing 'senderCertificate' field") - } - - // Simple Field (receiverCertificateThumbprint) - if pushErr := writeBuffer.PushContext("receiverCertificateThumbprint"); pushErr != nil { - return errors.Wrap(pushErr, "Error pushing for receiverCertificateThumbprint") - } - _receiverCertificateThumbprintErr := writeBuffer.WriteSerializable(ctx, m.GetReceiverCertificateThumbprint()) - if popErr := writeBuffer.PopContext("receiverCertificateThumbprint"); popErr != nil { - return errors.Wrap(popErr, "Error popping for receiverCertificateThumbprint") - } - if _receiverCertificateThumbprintErr != nil { - return errors.Wrap(_receiverCertificateThumbprintErr, "Error serializing 'receiverCertificateThumbprint' field") - } - - // Simple Field (sequenceNumber) - sequenceNumber := int32(m.GetSequenceNumber()) - _sequenceNumberErr := writeBuffer.WriteInt32("sequenceNumber", 32, int32((sequenceNumber))) - if _sequenceNumberErr != nil { - return errors.Wrap(_sequenceNumberErr, "Error serializing 'sequenceNumber' field") - } - - // Simple Field (requestId) - requestId := int32(m.GetRequestId()) - _requestIdErr := writeBuffer.WriteInt32("requestId", 32, int32((requestId))) - if _requestIdErr != nil { - return errors.Wrap(_requestIdErr, "Error serializing 'requestId' field") - } - - // Array Field (message) - // Byte Array field (message) - if err := writeBuffer.WriteByteArray("message", m.GetMessage()); err != nil { - return errors.Wrap(err, "Error serializing 'message' field") + if _messageErr != nil { + return errors.Wrap(_messageErr, "Error serializing 'message' field") } if popErr := writeBuffer.PopContext("OpcuaOpenResponse"); popErr != nil { @@ -428,6 +249,16 @@ func (m *_OpcuaOpenResponse) SerializeWithWriteBuffer(ctx context.Context, write return m.SerializeParent(ctx, writeBuffer, m, ser) } +//// +// Arguments Getter + +func (m *_OpcuaOpenResponse) GetTotalLength() uint32 { + return m.TotalLength +} + +// +//// + func (m *_OpcuaOpenResponse) isOpcuaOpenResponse() bool { return true } diff --git a/plc4go/protocols/opcua/readwrite/model/OpcuaProtocolLimits.go b/plc4go/protocols/opcua/readwrite/model/OpcuaProtocolLimits.go new file mode 100644 index 00000000000..45e5124fb9f --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/OpcuaProtocolLimits.go @@ -0,0 +1,250 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + "github.com/apache/plc4x/plc4go/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// OpcuaProtocolLimits is the corresponding interface of OpcuaProtocolLimits +type OpcuaProtocolLimits interface { + fmt.Stringer + utils.LengthAware + utils.Serializable + // GetReceiveBufferSize returns ReceiveBufferSize (property field) + GetReceiveBufferSize() uint32 + // GetSendBufferSize returns SendBufferSize (property field) + GetSendBufferSize() uint32 + // GetMaxMessageSize returns MaxMessageSize (property field) + GetMaxMessageSize() uint32 + // GetMaxChunkCount returns MaxChunkCount (property field) + GetMaxChunkCount() uint32 +} + +// OpcuaProtocolLimitsExactly can be used when we want exactly this type and not a type which fulfills OpcuaProtocolLimits. +// This is useful for switch cases. +type OpcuaProtocolLimitsExactly interface { + OpcuaProtocolLimits + isOpcuaProtocolLimits() bool +} + +// _OpcuaProtocolLimits is the data-structure of this message +type _OpcuaProtocolLimits struct { + ReceiveBufferSize uint32 + SendBufferSize uint32 + MaxMessageSize uint32 + MaxChunkCount uint32 +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_OpcuaProtocolLimits) GetReceiveBufferSize() uint32 { + return m.ReceiveBufferSize +} + +func (m *_OpcuaProtocolLimits) GetSendBufferSize() uint32 { + return m.SendBufferSize +} + +func (m *_OpcuaProtocolLimits) GetMaxMessageSize() uint32 { + return m.MaxMessageSize +} + +func (m *_OpcuaProtocolLimits) GetMaxChunkCount() uint32 { + return m.MaxChunkCount +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewOpcuaProtocolLimits factory function for _OpcuaProtocolLimits +func NewOpcuaProtocolLimits(receiveBufferSize uint32, sendBufferSize uint32, maxMessageSize uint32, maxChunkCount uint32) *_OpcuaProtocolLimits { + return &_OpcuaProtocolLimits{ReceiveBufferSize: receiveBufferSize, SendBufferSize: sendBufferSize, MaxMessageSize: maxMessageSize, MaxChunkCount: maxChunkCount} +} + +// Deprecated: use the interface for direct cast +func CastOpcuaProtocolLimits(structType any) OpcuaProtocolLimits { + if casted, ok := structType.(OpcuaProtocolLimits); ok { + return casted + } + if casted, ok := structType.(*OpcuaProtocolLimits); ok { + return *casted + } + return nil +} + +func (m *_OpcuaProtocolLimits) GetTypeName() string { + return "OpcuaProtocolLimits" +} + +func (m *_OpcuaProtocolLimits) GetLengthInBits(ctx context.Context) uint16 { + lengthInBits := uint16(0) + + // Simple field (receiveBufferSize) + lengthInBits += 32 + + // Simple field (sendBufferSize) + lengthInBits += 32 + + // Simple field (maxMessageSize) + lengthInBits += 32 + + // Simple field (maxChunkCount) + lengthInBits += 32 + + return lengthInBits +} + +func (m *_OpcuaProtocolLimits) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func OpcuaProtocolLimitsParse(ctx context.Context, theBytes []byte) (OpcuaProtocolLimits, error) { + return OpcuaProtocolLimitsParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes)) +} + +func OpcuaProtocolLimitsParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) (OpcuaProtocolLimits, error) { + positionAware := readBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pullErr := readBuffer.PullContext("OpcuaProtocolLimits"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for OpcuaProtocolLimits") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Simple Field (receiveBufferSize) + _receiveBufferSize, _receiveBufferSizeErr := readBuffer.ReadUint32("receiveBufferSize", 32) + if _receiveBufferSizeErr != nil { + return nil, errors.Wrap(_receiveBufferSizeErr, "Error parsing 'receiveBufferSize' field of OpcuaProtocolLimits") + } + receiveBufferSize := _receiveBufferSize + + // Simple Field (sendBufferSize) + _sendBufferSize, _sendBufferSizeErr := readBuffer.ReadUint32("sendBufferSize", 32) + if _sendBufferSizeErr != nil { + return nil, errors.Wrap(_sendBufferSizeErr, "Error parsing 'sendBufferSize' field of OpcuaProtocolLimits") + } + sendBufferSize := _sendBufferSize + + // Simple Field (maxMessageSize) + _maxMessageSize, _maxMessageSizeErr := readBuffer.ReadUint32("maxMessageSize", 32) + if _maxMessageSizeErr != nil { + return nil, errors.Wrap(_maxMessageSizeErr, "Error parsing 'maxMessageSize' field of OpcuaProtocolLimits") + } + maxMessageSize := _maxMessageSize + + // Simple Field (maxChunkCount) + _maxChunkCount, _maxChunkCountErr := readBuffer.ReadUint32("maxChunkCount", 32) + if _maxChunkCountErr != nil { + return nil, errors.Wrap(_maxChunkCountErr, "Error parsing 'maxChunkCount' field of OpcuaProtocolLimits") + } + maxChunkCount := _maxChunkCount + + if closeErr := readBuffer.CloseContext("OpcuaProtocolLimits"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for OpcuaProtocolLimits") + } + + // Create the instance + return &_OpcuaProtocolLimits{ + ReceiveBufferSize: receiveBufferSize, + SendBufferSize: sendBufferSize, + MaxMessageSize: maxMessageSize, + MaxChunkCount: maxChunkCount, + }, nil +} + +func (m *_OpcuaProtocolLimits) Serialize() ([]byte, error) { + wb := utils.NewWriteBufferByteBased(utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes(context.Background())))) + if err := m.SerializeWithWriteBuffer(context.Background(), wb); err != nil { + return nil, err + } + return wb.GetBytes(), nil +} + +func (m *_OpcuaProtocolLimits) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { + positionAware := writeBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pushErr := writeBuffer.PushContext("OpcuaProtocolLimits"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for OpcuaProtocolLimits") + } + + // Simple Field (receiveBufferSize) + receiveBufferSize := uint32(m.GetReceiveBufferSize()) + _receiveBufferSizeErr := writeBuffer.WriteUint32("receiveBufferSize", 32, uint32((receiveBufferSize))) + if _receiveBufferSizeErr != nil { + return errors.Wrap(_receiveBufferSizeErr, "Error serializing 'receiveBufferSize' field") + } + + // Simple Field (sendBufferSize) + sendBufferSize := uint32(m.GetSendBufferSize()) + _sendBufferSizeErr := writeBuffer.WriteUint32("sendBufferSize", 32, uint32((sendBufferSize))) + if _sendBufferSizeErr != nil { + return errors.Wrap(_sendBufferSizeErr, "Error serializing 'sendBufferSize' field") + } + + // Simple Field (maxMessageSize) + maxMessageSize := uint32(m.GetMaxMessageSize()) + _maxMessageSizeErr := writeBuffer.WriteUint32("maxMessageSize", 32, uint32((maxMessageSize))) + if _maxMessageSizeErr != nil { + return errors.Wrap(_maxMessageSizeErr, "Error serializing 'maxMessageSize' field") + } + + // Simple Field (maxChunkCount) + maxChunkCount := uint32(m.GetMaxChunkCount()) + _maxChunkCountErr := writeBuffer.WriteUint32("maxChunkCount", 32, uint32((maxChunkCount))) + if _maxChunkCountErr != nil { + return errors.Wrap(_maxChunkCountErr, "Error serializing 'maxChunkCount' field") + } + + if popErr := writeBuffer.PopContext("OpcuaProtocolLimits"); popErr != nil { + return errors.Wrap(popErr, "Error popping for OpcuaProtocolLimits") + } + return nil +} + +func (m *_OpcuaProtocolLimits) isOpcuaProtocolLimits() bool { + return true +} + +func (m *_OpcuaProtocolLimits) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) + if err := writeBuffer.WriteSerializable(context.Background(), m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/opcua/readwrite/model/OpenChannelMessage.go b/plc4go/protocols/opcua/readwrite/model/OpenChannelMessage.go new file mode 100644 index 00000000000..de216d87111 --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/OpenChannelMessage.go @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + "github.com/apache/plc4x/plc4go/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// OpenChannelMessage is the corresponding interface of OpenChannelMessage +type OpenChannelMessage interface { + fmt.Stringer + utils.LengthAware + utils.Serializable + // GetResponse returns Response (discriminator field) + GetResponse() bool +} + +// OpenChannelMessageExactly can be used when we want exactly this type and not a type which fulfills OpenChannelMessage. +// This is useful for switch cases. +type OpenChannelMessageExactly interface { + OpenChannelMessage + isOpenChannelMessage() bool +} + +// _OpenChannelMessage is the data-structure of this message +type _OpenChannelMessage struct { + _OpenChannelMessageChildRequirements +} + +type _OpenChannelMessageChildRequirements interface { + utils.Serializable + GetLengthInBits(ctx context.Context) uint16 + GetResponse() bool +} + +type OpenChannelMessageParent interface { + SerializeParent(ctx context.Context, writeBuffer utils.WriteBuffer, child OpenChannelMessage, serializeChildFunction func() error) error + GetTypeName() string +} + +type OpenChannelMessageChild interface { + utils.Serializable + InitializeParent(parent OpenChannelMessage) + GetParent() *OpenChannelMessage + + GetTypeName() string + OpenChannelMessage +} + +// NewOpenChannelMessage factory function for _OpenChannelMessage +func NewOpenChannelMessage() *_OpenChannelMessage { + return &_OpenChannelMessage{} +} + +// Deprecated: use the interface for direct cast +func CastOpenChannelMessage(structType any) OpenChannelMessage { + if casted, ok := structType.(OpenChannelMessage); ok { + return casted + } + if casted, ok := structType.(*OpenChannelMessage); ok { + return *casted + } + return nil +} + +func (m *_OpenChannelMessage) GetTypeName() string { + return "OpenChannelMessage" +} + +func (m *_OpenChannelMessage) GetParentLengthInBits(ctx context.Context) uint16 { + lengthInBits := uint16(0) + + return lengthInBits +} + +func (m *_OpenChannelMessage) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func OpenChannelMessageParse(ctx context.Context, theBytes []byte, response bool) (OpenChannelMessage, error) { + return OpenChannelMessageParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), response) +} + +func OpenChannelMessageParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, response bool) (OpenChannelMessage, error) { + positionAware := readBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pullErr := readBuffer.PullContext("OpenChannelMessage"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for OpenChannelMessage") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) + type OpenChannelMessageChildSerializeRequirement interface { + OpenChannelMessage + InitializeParent(OpenChannelMessage) + GetParent() OpenChannelMessage + } + var _childTemp any + var _child OpenChannelMessageChildSerializeRequirement + var typeSwitchError error + switch { + case response == bool(false): // OpenChannelMessageRequest + _childTemp, typeSwitchError = OpenChannelMessageRequestParseWithBuffer(ctx, readBuffer, response) + case response == bool(true): // OpenChannelMessageResponse + _childTemp, typeSwitchError = OpenChannelMessageResponseParseWithBuffer(ctx, readBuffer, response) + default: + typeSwitchError = errors.Errorf("Unmapped type for parameters [response=%v]", response) + } + if typeSwitchError != nil { + return nil, errors.Wrap(typeSwitchError, "Error parsing sub-type for type-switch of OpenChannelMessage") + } + _child = _childTemp.(OpenChannelMessageChildSerializeRequirement) + + if closeErr := readBuffer.CloseContext("OpenChannelMessage"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for OpenChannelMessage") + } + + // Finish initializing + _child.InitializeParent(_child) + return _child, nil +} + +func (pm *_OpenChannelMessage) SerializeParent(ctx context.Context, writeBuffer utils.WriteBuffer, child OpenChannelMessage, serializeChildFunction func() error) error { + // We redirect all calls through client as some methods are only implemented there + m := child + _ = m + positionAware := writeBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pushErr := writeBuffer.PushContext("OpenChannelMessage"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for OpenChannelMessage") + } + + // Switch field (Depending on the discriminator values, passes the serialization to a sub-type) + if _typeSwitchErr := serializeChildFunction(); _typeSwitchErr != nil { + return errors.Wrap(_typeSwitchErr, "Error serializing sub-type field") + } + + if popErr := writeBuffer.PopContext("OpenChannelMessage"); popErr != nil { + return errors.Wrap(popErr, "Error popping for OpenChannelMessage") + } + return nil +} + +func (m *_OpenChannelMessage) isOpenChannelMessage() bool { + return true +} + +func (m *_OpenChannelMessage) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) + if err := writeBuffer.WriteSerializable(context.Background(), m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/opcua/readwrite/model/OpenChannelMessageRequest.go b/plc4go/protocols/opcua/readwrite/model/OpenChannelMessageRequest.go new file mode 100644 index 00000000000..cf7f9206ce7 --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/OpenChannelMessageRequest.go @@ -0,0 +1,319 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + "github.com/apache/plc4x/plc4go/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// OpenChannelMessageRequest is the corresponding interface of OpenChannelMessageRequest +type OpenChannelMessageRequest interface { + fmt.Stringer + utils.LengthAware + utils.Serializable + OpenChannelMessage + // GetSecureChannelId returns SecureChannelId (property field) + GetSecureChannelId() int32 + // GetEndpoint returns Endpoint (property field) + GetEndpoint() PascalString + // GetSenderCertificate returns SenderCertificate (property field) + GetSenderCertificate() PascalByteString + // GetReceiverCertificateThumbprint returns ReceiverCertificateThumbprint (property field) + GetReceiverCertificateThumbprint() PascalByteString +} + +// OpenChannelMessageRequestExactly can be used when we want exactly this type and not a type which fulfills OpenChannelMessageRequest. +// This is useful for switch cases. +type OpenChannelMessageRequestExactly interface { + OpenChannelMessageRequest + isOpenChannelMessageRequest() bool +} + +// _OpenChannelMessageRequest is the data-structure of this message +type _OpenChannelMessageRequest struct { + *_OpenChannelMessage + SecureChannelId int32 + Endpoint PascalString + SenderCertificate PascalByteString + ReceiverCertificateThumbprint PascalByteString +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for discriminator values. +/////////////////////// + +func (m *_OpenChannelMessageRequest) GetResponse() bool { + return bool(false) +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +func (m *_OpenChannelMessageRequest) InitializeParent(parent OpenChannelMessage) {} + +func (m *_OpenChannelMessageRequest) GetParent() OpenChannelMessage { + return m._OpenChannelMessage +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_OpenChannelMessageRequest) GetSecureChannelId() int32 { + return m.SecureChannelId +} + +func (m *_OpenChannelMessageRequest) GetEndpoint() PascalString { + return m.Endpoint +} + +func (m *_OpenChannelMessageRequest) GetSenderCertificate() PascalByteString { + return m.SenderCertificate +} + +func (m *_OpenChannelMessageRequest) GetReceiverCertificateThumbprint() PascalByteString { + return m.ReceiverCertificateThumbprint +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewOpenChannelMessageRequest factory function for _OpenChannelMessageRequest +func NewOpenChannelMessageRequest(secureChannelId int32, endpoint PascalString, senderCertificate PascalByteString, receiverCertificateThumbprint PascalByteString) *_OpenChannelMessageRequest { + _result := &_OpenChannelMessageRequest{ + SecureChannelId: secureChannelId, + Endpoint: endpoint, + SenderCertificate: senderCertificate, + ReceiverCertificateThumbprint: receiverCertificateThumbprint, + _OpenChannelMessage: NewOpenChannelMessage(), + } + _result._OpenChannelMessage._OpenChannelMessageChildRequirements = _result + return _result +} + +// Deprecated: use the interface for direct cast +func CastOpenChannelMessageRequest(structType any) OpenChannelMessageRequest { + if casted, ok := structType.(OpenChannelMessageRequest); ok { + return casted + } + if casted, ok := structType.(*OpenChannelMessageRequest); ok { + return *casted + } + return nil +} + +func (m *_OpenChannelMessageRequest) GetTypeName() string { + return "OpenChannelMessageRequest" +} + +func (m *_OpenChannelMessageRequest) GetLengthInBits(ctx context.Context) uint16 { + lengthInBits := uint16(m.GetParentLengthInBits(ctx)) + + // Simple field (secureChannelId) + lengthInBits += 32 + + // Simple field (endpoint) + lengthInBits += m.Endpoint.GetLengthInBits(ctx) + + // Simple field (senderCertificate) + lengthInBits += m.SenderCertificate.GetLengthInBits(ctx) + + // Simple field (receiverCertificateThumbprint) + lengthInBits += m.ReceiverCertificateThumbprint.GetLengthInBits(ctx) + + return lengthInBits +} + +func (m *_OpenChannelMessageRequest) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func OpenChannelMessageRequestParse(ctx context.Context, theBytes []byte, response bool) (OpenChannelMessageRequest, error) { + return OpenChannelMessageRequestParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), response) +} + +func OpenChannelMessageRequestParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, response bool) (OpenChannelMessageRequest, error) { + positionAware := readBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pullErr := readBuffer.PullContext("OpenChannelMessageRequest"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for OpenChannelMessageRequest") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Simple Field (secureChannelId) + _secureChannelId, _secureChannelIdErr := readBuffer.ReadInt32("secureChannelId", 32) + if _secureChannelIdErr != nil { + return nil, errors.Wrap(_secureChannelIdErr, "Error parsing 'secureChannelId' field of OpenChannelMessageRequest") + } + secureChannelId := _secureChannelId + + // Simple Field (endpoint) + if pullErr := readBuffer.PullContext("endpoint"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for endpoint") + } + _endpoint, _endpointErr := PascalStringParseWithBuffer(ctx, readBuffer) + if _endpointErr != nil { + return nil, errors.Wrap(_endpointErr, "Error parsing 'endpoint' field of OpenChannelMessageRequest") + } + endpoint := _endpoint.(PascalString) + if closeErr := readBuffer.CloseContext("endpoint"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for endpoint") + } + + // Simple Field (senderCertificate) + if pullErr := readBuffer.PullContext("senderCertificate"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for senderCertificate") + } + _senderCertificate, _senderCertificateErr := PascalByteStringParseWithBuffer(ctx, readBuffer) + if _senderCertificateErr != nil { + return nil, errors.Wrap(_senderCertificateErr, "Error parsing 'senderCertificate' field of OpenChannelMessageRequest") + } + senderCertificate := _senderCertificate.(PascalByteString) + if closeErr := readBuffer.CloseContext("senderCertificate"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for senderCertificate") + } + + // Simple Field (receiverCertificateThumbprint) + if pullErr := readBuffer.PullContext("receiverCertificateThumbprint"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for receiverCertificateThumbprint") + } + _receiverCertificateThumbprint, _receiverCertificateThumbprintErr := PascalByteStringParseWithBuffer(ctx, readBuffer) + if _receiverCertificateThumbprintErr != nil { + return nil, errors.Wrap(_receiverCertificateThumbprintErr, "Error parsing 'receiverCertificateThumbprint' field of OpenChannelMessageRequest") + } + receiverCertificateThumbprint := _receiverCertificateThumbprint.(PascalByteString) + if closeErr := readBuffer.CloseContext("receiverCertificateThumbprint"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for receiverCertificateThumbprint") + } + + if closeErr := readBuffer.CloseContext("OpenChannelMessageRequest"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for OpenChannelMessageRequest") + } + + // Create a partially initialized instance + _child := &_OpenChannelMessageRequest{ + _OpenChannelMessage: &_OpenChannelMessage{}, + SecureChannelId: secureChannelId, + Endpoint: endpoint, + SenderCertificate: senderCertificate, + ReceiverCertificateThumbprint: receiverCertificateThumbprint, + } + _child._OpenChannelMessage._OpenChannelMessageChildRequirements = _child + return _child, nil +} + +func (m *_OpenChannelMessageRequest) Serialize() ([]byte, error) { + wb := utils.NewWriteBufferByteBased(utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes(context.Background())))) + if err := m.SerializeWithWriteBuffer(context.Background(), wb); err != nil { + return nil, err + } + return wb.GetBytes(), nil +} + +func (m *_OpenChannelMessageRequest) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { + positionAware := writeBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + ser := func() error { + if pushErr := writeBuffer.PushContext("OpenChannelMessageRequest"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for OpenChannelMessageRequest") + } + + // Simple Field (secureChannelId) + secureChannelId := int32(m.GetSecureChannelId()) + _secureChannelIdErr := writeBuffer.WriteInt32("secureChannelId", 32, int32((secureChannelId))) + if _secureChannelIdErr != nil { + return errors.Wrap(_secureChannelIdErr, "Error serializing 'secureChannelId' field") + } + + // Simple Field (endpoint) + if pushErr := writeBuffer.PushContext("endpoint"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for endpoint") + } + _endpointErr := writeBuffer.WriteSerializable(ctx, m.GetEndpoint()) + if popErr := writeBuffer.PopContext("endpoint"); popErr != nil { + return errors.Wrap(popErr, "Error popping for endpoint") + } + if _endpointErr != nil { + return errors.Wrap(_endpointErr, "Error serializing 'endpoint' field") + } + + // Simple Field (senderCertificate) + if pushErr := writeBuffer.PushContext("senderCertificate"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for senderCertificate") + } + _senderCertificateErr := writeBuffer.WriteSerializable(ctx, m.GetSenderCertificate()) + if popErr := writeBuffer.PopContext("senderCertificate"); popErr != nil { + return errors.Wrap(popErr, "Error popping for senderCertificate") + } + if _senderCertificateErr != nil { + return errors.Wrap(_senderCertificateErr, "Error serializing 'senderCertificate' field") + } + + // Simple Field (receiverCertificateThumbprint) + if pushErr := writeBuffer.PushContext("receiverCertificateThumbprint"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for receiverCertificateThumbprint") + } + _receiverCertificateThumbprintErr := writeBuffer.WriteSerializable(ctx, m.GetReceiverCertificateThumbprint()) + if popErr := writeBuffer.PopContext("receiverCertificateThumbprint"); popErr != nil { + return errors.Wrap(popErr, "Error popping for receiverCertificateThumbprint") + } + if _receiverCertificateThumbprintErr != nil { + return errors.Wrap(_receiverCertificateThumbprintErr, "Error serializing 'receiverCertificateThumbprint' field") + } + + if popErr := writeBuffer.PopContext("OpenChannelMessageRequest"); popErr != nil { + return errors.Wrap(popErr, "Error popping for OpenChannelMessageRequest") + } + return nil + } + return m.SerializeParent(ctx, writeBuffer, m, ser) +} + +func (m *_OpenChannelMessageRequest) isOpenChannelMessageRequest() bool { + return true +} + +func (m *_OpenChannelMessageRequest) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) + if err := writeBuffer.WriteSerializable(context.Background(), m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/opcua/readwrite/model/OpenChannelMessageResponse.go b/plc4go/protocols/opcua/readwrite/model/OpenChannelMessageResponse.go new file mode 100644 index 00000000000..35239f13b04 --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/OpenChannelMessageResponse.go @@ -0,0 +1,319 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + "github.com/apache/plc4x/plc4go/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// OpenChannelMessageResponse is the corresponding interface of OpenChannelMessageResponse +type OpenChannelMessageResponse interface { + fmt.Stringer + utils.LengthAware + utils.Serializable + OpenChannelMessage + // GetSecureChannelId returns SecureChannelId (property field) + GetSecureChannelId() int32 + // GetSecurityPolicyUri returns SecurityPolicyUri (property field) + GetSecurityPolicyUri() PascalString + // GetSenderCertificate returns SenderCertificate (property field) + GetSenderCertificate() PascalByteString + // GetReceiverCertificateThumbprint returns ReceiverCertificateThumbprint (property field) + GetReceiverCertificateThumbprint() PascalByteString +} + +// OpenChannelMessageResponseExactly can be used when we want exactly this type and not a type which fulfills OpenChannelMessageResponse. +// This is useful for switch cases. +type OpenChannelMessageResponseExactly interface { + OpenChannelMessageResponse + isOpenChannelMessageResponse() bool +} + +// _OpenChannelMessageResponse is the data-structure of this message +type _OpenChannelMessageResponse struct { + *_OpenChannelMessage + SecureChannelId int32 + SecurityPolicyUri PascalString + SenderCertificate PascalByteString + ReceiverCertificateThumbprint PascalByteString +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for discriminator values. +/////////////////////// + +func (m *_OpenChannelMessageResponse) GetResponse() bool { + return bool(true) +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +func (m *_OpenChannelMessageResponse) InitializeParent(parent OpenChannelMessage) {} + +func (m *_OpenChannelMessageResponse) GetParent() OpenChannelMessage { + return m._OpenChannelMessage +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_OpenChannelMessageResponse) GetSecureChannelId() int32 { + return m.SecureChannelId +} + +func (m *_OpenChannelMessageResponse) GetSecurityPolicyUri() PascalString { + return m.SecurityPolicyUri +} + +func (m *_OpenChannelMessageResponse) GetSenderCertificate() PascalByteString { + return m.SenderCertificate +} + +func (m *_OpenChannelMessageResponse) GetReceiverCertificateThumbprint() PascalByteString { + return m.ReceiverCertificateThumbprint +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewOpenChannelMessageResponse factory function for _OpenChannelMessageResponse +func NewOpenChannelMessageResponse(secureChannelId int32, securityPolicyUri PascalString, senderCertificate PascalByteString, receiverCertificateThumbprint PascalByteString) *_OpenChannelMessageResponse { + _result := &_OpenChannelMessageResponse{ + SecureChannelId: secureChannelId, + SecurityPolicyUri: securityPolicyUri, + SenderCertificate: senderCertificate, + ReceiverCertificateThumbprint: receiverCertificateThumbprint, + _OpenChannelMessage: NewOpenChannelMessage(), + } + _result._OpenChannelMessage._OpenChannelMessageChildRequirements = _result + return _result +} + +// Deprecated: use the interface for direct cast +func CastOpenChannelMessageResponse(structType any) OpenChannelMessageResponse { + if casted, ok := structType.(OpenChannelMessageResponse); ok { + return casted + } + if casted, ok := structType.(*OpenChannelMessageResponse); ok { + return *casted + } + return nil +} + +func (m *_OpenChannelMessageResponse) GetTypeName() string { + return "OpenChannelMessageResponse" +} + +func (m *_OpenChannelMessageResponse) GetLengthInBits(ctx context.Context) uint16 { + lengthInBits := uint16(m.GetParentLengthInBits(ctx)) + + // Simple field (secureChannelId) + lengthInBits += 32 + + // Simple field (securityPolicyUri) + lengthInBits += m.SecurityPolicyUri.GetLengthInBits(ctx) + + // Simple field (senderCertificate) + lengthInBits += m.SenderCertificate.GetLengthInBits(ctx) + + // Simple field (receiverCertificateThumbprint) + lengthInBits += m.ReceiverCertificateThumbprint.GetLengthInBits(ctx) + + return lengthInBits +} + +func (m *_OpenChannelMessageResponse) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func OpenChannelMessageResponseParse(ctx context.Context, theBytes []byte, response bool) (OpenChannelMessageResponse, error) { + return OpenChannelMessageResponseParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), response) +} + +func OpenChannelMessageResponseParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, response bool) (OpenChannelMessageResponse, error) { + positionAware := readBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pullErr := readBuffer.PullContext("OpenChannelMessageResponse"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for OpenChannelMessageResponse") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Simple Field (secureChannelId) + _secureChannelId, _secureChannelIdErr := readBuffer.ReadInt32("secureChannelId", 32) + if _secureChannelIdErr != nil { + return nil, errors.Wrap(_secureChannelIdErr, "Error parsing 'secureChannelId' field of OpenChannelMessageResponse") + } + secureChannelId := _secureChannelId + + // Simple Field (securityPolicyUri) + if pullErr := readBuffer.PullContext("securityPolicyUri"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for securityPolicyUri") + } + _securityPolicyUri, _securityPolicyUriErr := PascalStringParseWithBuffer(ctx, readBuffer) + if _securityPolicyUriErr != nil { + return nil, errors.Wrap(_securityPolicyUriErr, "Error parsing 'securityPolicyUri' field of OpenChannelMessageResponse") + } + securityPolicyUri := _securityPolicyUri.(PascalString) + if closeErr := readBuffer.CloseContext("securityPolicyUri"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for securityPolicyUri") + } + + // Simple Field (senderCertificate) + if pullErr := readBuffer.PullContext("senderCertificate"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for senderCertificate") + } + _senderCertificate, _senderCertificateErr := PascalByteStringParseWithBuffer(ctx, readBuffer) + if _senderCertificateErr != nil { + return nil, errors.Wrap(_senderCertificateErr, "Error parsing 'senderCertificate' field of OpenChannelMessageResponse") + } + senderCertificate := _senderCertificate.(PascalByteString) + if closeErr := readBuffer.CloseContext("senderCertificate"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for senderCertificate") + } + + // Simple Field (receiverCertificateThumbprint) + if pullErr := readBuffer.PullContext("receiverCertificateThumbprint"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for receiverCertificateThumbprint") + } + _receiverCertificateThumbprint, _receiverCertificateThumbprintErr := PascalByteStringParseWithBuffer(ctx, readBuffer) + if _receiverCertificateThumbprintErr != nil { + return nil, errors.Wrap(_receiverCertificateThumbprintErr, "Error parsing 'receiverCertificateThumbprint' field of OpenChannelMessageResponse") + } + receiverCertificateThumbprint := _receiverCertificateThumbprint.(PascalByteString) + if closeErr := readBuffer.CloseContext("receiverCertificateThumbprint"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for receiverCertificateThumbprint") + } + + if closeErr := readBuffer.CloseContext("OpenChannelMessageResponse"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for OpenChannelMessageResponse") + } + + // Create a partially initialized instance + _child := &_OpenChannelMessageResponse{ + _OpenChannelMessage: &_OpenChannelMessage{}, + SecureChannelId: secureChannelId, + SecurityPolicyUri: securityPolicyUri, + SenderCertificate: senderCertificate, + ReceiverCertificateThumbprint: receiverCertificateThumbprint, + } + _child._OpenChannelMessage._OpenChannelMessageChildRequirements = _child + return _child, nil +} + +func (m *_OpenChannelMessageResponse) Serialize() ([]byte, error) { + wb := utils.NewWriteBufferByteBased(utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes(context.Background())))) + if err := m.SerializeWithWriteBuffer(context.Background(), wb); err != nil { + return nil, err + } + return wb.GetBytes(), nil +} + +func (m *_OpenChannelMessageResponse) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { + positionAware := writeBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + ser := func() error { + if pushErr := writeBuffer.PushContext("OpenChannelMessageResponse"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for OpenChannelMessageResponse") + } + + // Simple Field (secureChannelId) + secureChannelId := int32(m.GetSecureChannelId()) + _secureChannelIdErr := writeBuffer.WriteInt32("secureChannelId", 32, int32((secureChannelId))) + if _secureChannelIdErr != nil { + return errors.Wrap(_secureChannelIdErr, "Error serializing 'secureChannelId' field") + } + + // Simple Field (securityPolicyUri) + if pushErr := writeBuffer.PushContext("securityPolicyUri"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for securityPolicyUri") + } + _securityPolicyUriErr := writeBuffer.WriteSerializable(ctx, m.GetSecurityPolicyUri()) + if popErr := writeBuffer.PopContext("securityPolicyUri"); popErr != nil { + return errors.Wrap(popErr, "Error popping for securityPolicyUri") + } + if _securityPolicyUriErr != nil { + return errors.Wrap(_securityPolicyUriErr, "Error serializing 'securityPolicyUri' field") + } + + // Simple Field (senderCertificate) + if pushErr := writeBuffer.PushContext("senderCertificate"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for senderCertificate") + } + _senderCertificateErr := writeBuffer.WriteSerializable(ctx, m.GetSenderCertificate()) + if popErr := writeBuffer.PopContext("senderCertificate"); popErr != nil { + return errors.Wrap(popErr, "Error popping for senderCertificate") + } + if _senderCertificateErr != nil { + return errors.Wrap(_senderCertificateErr, "Error serializing 'senderCertificate' field") + } + + // Simple Field (receiverCertificateThumbprint) + if pushErr := writeBuffer.PushContext("receiverCertificateThumbprint"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for receiverCertificateThumbprint") + } + _receiverCertificateThumbprintErr := writeBuffer.WriteSerializable(ctx, m.GetReceiverCertificateThumbprint()) + if popErr := writeBuffer.PopContext("receiverCertificateThumbprint"); popErr != nil { + return errors.Wrap(popErr, "Error popping for receiverCertificateThumbprint") + } + if _receiverCertificateThumbprintErr != nil { + return errors.Wrap(_receiverCertificateThumbprintErr, "Error serializing 'receiverCertificateThumbprint' field") + } + + if popErr := writeBuffer.PopContext("OpenChannelMessageResponse"); popErr != nil { + return errors.Wrap(popErr, "Error popping for OpenChannelMessageResponse") + } + return nil + } + return m.SerializeParent(ctx, writeBuffer, m, ser) +} + +func (m *_OpenChannelMessageResponse) isOpenChannelMessageResponse() bool { + return true +} + +func (m *_OpenChannelMessageResponse) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) + if err := writeBuffer.WriteSerializable(context.Background(), m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/opcua/readwrite/model/Payload.go b/plc4go/protocols/opcua/readwrite/model/Payload.go new file mode 100644 index 00000000000..b3bf97acaf0 --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/Payload.go @@ -0,0 +1,243 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + "github.com/apache/plc4x/plc4go/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// Payload is the corresponding interface of Payload +type Payload interface { + fmt.Stringer + utils.LengthAware + utils.Serializable + // GetExtensible returns Extensible (discriminator field) + GetExtensible() bool + // GetSequenceHeader returns SequenceHeader (property field) + GetSequenceHeader() SequenceHeader +} + +// PayloadExactly can be used when we want exactly this type and not a type which fulfills Payload. +// This is useful for switch cases. +type PayloadExactly interface { + Payload + isPayload() bool +} + +// _Payload is the data-structure of this message +type _Payload struct { + _PayloadChildRequirements + SequenceHeader SequenceHeader + + // Arguments. + ByteCount uint32 +} + +type _PayloadChildRequirements interface { + utils.Serializable + GetLengthInBits(ctx context.Context) uint16 + GetExtensible() bool +} + +type PayloadParent interface { + SerializeParent(ctx context.Context, writeBuffer utils.WriteBuffer, child Payload, serializeChildFunction func() error) error + GetTypeName() string +} + +type PayloadChild interface { + utils.Serializable + InitializeParent(parent Payload, sequenceHeader SequenceHeader) + GetParent() *Payload + + GetTypeName() string + Payload +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_Payload) GetSequenceHeader() SequenceHeader { + return m.SequenceHeader +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewPayload factory function for _Payload +func NewPayload(sequenceHeader SequenceHeader, byteCount uint32) *_Payload { + return &_Payload{SequenceHeader: sequenceHeader, ByteCount: byteCount} +} + +// Deprecated: use the interface for direct cast +func CastPayload(structType any) Payload { + if casted, ok := structType.(Payload); ok { + return casted + } + if casted, ok := structType.(*Payload); ok { + return *casted + } + return nil +} + +func (m *_Payload) GetTypeName() string { + return "Payload" +} + +func (m *_Payload) GetParentLengthInBits(ctx context.Context) uint16 { + lengthInBits := uint16(0) + + // Simple field (sequenceHeader) + lengthInBits += m.SequenceHeader.GetLengthInBits(ctx) + + return lengthInBits +} + +func (m *_Payload) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func PayloadParse(ctx context.Context, theBytes []byte, extensible bool, byteCount uint32) (Payload, error) { + return PayloadParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), extensible, byteCount) +} + +func PayloadParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, extensible bool, byteCount uint32) (Payload, error) { + positionAware := readBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pullErr := readBuffer.PullContext("Payload"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for Payload") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Simple Field (sequenceHeader) + if pullErr := readBuffer.PullContext("sequenceHeader"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for sequenceHeader") + } + _sequenceHeader, _sequenceHeaderErr := SequenceHeaderParseWithBuffer(ctx, readBuffer) + if _sequenceHeaderErr != nil { + return nil, errors.Wrap(_sequenceHeaderErr, "Error parsing 'sequenceHeader' field of Payload") + } + sequenceHeader := _sequenceHeader.(SequenceHeader) + if closeErr := readBuffer.CloseContext("sequenceHeader"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for sequenceHeader") + } + + // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) + type PayloadChildSerializeRequirement interface { + Payload + InitializeParent(Payload, SequenceHeader) + GetParent() Payload + } + var _childTemp any + var _child PayloadChildSerializeRequirement + var typeSwitchError error + switch { + case extensible == bool(true): // ExtensiblePayload + _childTemp, typeSwitchError = ExtensiblePayloadParseWithBuffer(ctx, readBuffer, extensible, byteCount) + case extensible == bool(false): // BinaryPayload + _childTemp, typeSwitchError = BinaryPayloadParseWithBuffer(ctx, readBuffer, extensible, byteCount) + default: + typeSwitchError = errors.Errorf("Unmapped type for parameters [extensible=%v]", extensible) + } + if typeSwitchError != nil { + return nil, errors.Wrap(typeSwitchError, "Error parsing sub-type for type-switch of Payload") + } + _child = _childTemp.(PayloadChildSerializeRequirement) + + if closeErr := readBuffer.CloseContext("Payload"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for Payload") + } + + // Finish initializing + _child.InitializeParent(_child, sequenceHeader) + return _child, nil +} + +func (pm *_Payload) SerializeParent(ctx context.Context, writeBuffer utils.WriteBuffer, child Payload, serializeChildFunction func() error) error { + // We redirect all calls through client as some methods are only implemented there + m := child + _ = m + positionAware := writeBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pushErr := writeBuffer.PushContext("Payload"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for Payload") + } + + // Simple Field (sequenceHeader) + if pushErr := writeBuffer.PushContext("sequenceHeader"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for sequenceHeader") + } + _sequenceHeaderErr := writeBuffer.WriteSerializable(ctx, m.GetSequenceHeader()) + if popErr := writeBuffer.PopContext("sequenceHeader"); popErr != nil { + return errors.Wrap(popErr, "Error popping for sequenceHeader") + } + if _sequenceHeaderErr != nil { + return errors.Wrap(_sequenceHeaderErr, "Error serializing 'sequenceHeader' field") + } + + // Switch field (Depending on the discriminator values, passes the serialization to a sub-type) + if _typeSwitchErr := serializeChildFunction(); _typeSwitchErr != nil { + return errors.Wrap(_typeSwitchErr, "Error serializing sub-type field") + } + + if popErr := writeBuffer.PopContext("Payload"); popErr != nil { + return errors.Wrap(popErr, "Error popping for Payload") + } + return nil +} + +//// +// Arguments Getter + +func (m *_Payload) GetByteCount() uint32 { + return m.ByteCount +} + +// +//// + +func (m *_Payload) isPayload() bool { + return true +} + +func (m *_Payload) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) + if err := writeBuffer.WriteSerializable(context.Background(), m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/opcua/readwrite/model/SecurityHeader.go b/plc4go/protocols/opcua/readwrite/model/SecurityHeader.go new file mode 100644 index 00000000000..3afe4ada31c --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/SecurityHeader.go @@ -0,0 +1,200 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + "github.com/apache/plc4x/plc4go/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// SecurityHeader is the corresponding interface of SecurityHeader +type SecurityHeader interface { + fmt.Stringer + utils.LengthAware + utils.Serializable + // GetSecureChannelId returns SecureChannelId (property field) + GetSecureChannelId() uint32 + // GetSecureTokenId returns SecureTokenId (property field) + GetSecureTokenId() uint32 +} + +// SecurityHeaderExactly can be used when we want exactly this type and not a type which fulfills SecurityHeader. +// This is useful for switch cases. +type SecurityHeaderExactly interface { + SecurityHeader + isSecurityHeader() bool +} + +// _SecurityHeader is the data-structure of this message +type _SecurityHeader struct { + SecureChannelId uint32 + SecureTokenId uint32 +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_SecurityHeader) GetSecureChannelId() uint32 { + return m.SecureChannelId +} + +func (m *_SecurityHeader) GetSecureTokenId() uint32 { + return m.SecureTokenId +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewSecurityHeader factory function for _SecurityHeader +func NewSecurityHeader(secureChannelId uint32, secureTokenId uint32) *_SecurityHeader { + return &_SecurityHeader{SecureChannelId: secureChannelId, SecureTokenId: secureTokenId} +} + +// Deprecated: use the interface for direct cast +func CastSecurityHeader(structType any) SecurityHeader { + if casted, ok := structType.(SecurityHeader); ok { + return casted + } + if casted, ok := structType.(*SecurityHeader); ok { + return *casted + } + return nil +} + +func (m *_SecurityHeader) GetTypeName() string { + return "SecurityHeader" +} + +func (m *_SecurityHeader) GetLengthInBits(ctx context.Context) uint16 { + lengthInBits := uint16(0) + + // Simple field (secureChannelId) + lengthInBits += 32 + + // Simple field (secureTokenId) + lengthInBits += 32 + + return lengthInBits +} + +func (m *_SecurityHeader) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func SecurityHeaderParse(ctx context.Context, theBytes []byte) (SecurityHeader, error) { + return SecurityHeaderParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes)) +} + +func SecurityHeaderParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) (SecurityHeader, error) { + positionAware := readBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pullErr := readBuffer.PullContext("SecurityHeader"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for SecurityHeader") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Simple Field (secureChannelId) + _secureChannelId, _secureChannelIdErr := readBuffer.ReadUint32("secureChannelId", 32) + if _secureChannelIdErr != nil { + return nil, errors.Wrap(_secureChannelIdErr, "Error parsing 'secureChannelId' field of SecurityHeader") + } + secureChannelId := _secureChannelId + + // Simple Field (secureTokenId) + _secureTokenId, _secureTokenIdErr := readBuffer.ReadUint32("secureTokenId", 32) + if _secureTokenIdErr != nil { + return nil, errors.Wrap(_secureTokenIdErr, "Error parsing 'secureTokenId' field of SecurityHeader") + } + secureTokenId := _secureTokenId + + if closeErr := readBuffer.CloseContext("SecurityHeader"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for SecurityHeader") + } + + // Create the instance + return &_SecurityHeader{ + SecureChannelId: secureChannelId, + SecureTokenId: secureTokenId, + }, nil +} + +func (m *_SecurityHeader) Serialize() ([]byte, error) { + wb := utils.NewWriteBufferByteBased(utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes(context.Background())))) + if err := m.SerializeWithWriteBuffer(context.Background(), wb); err != nil { + return nil, err + } + return wb.GetBytes(), nil +} + +func (m *_SecurityHeader) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { + positionAware := writeBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pushErr := writeBuffer.PushContext("SecurityHeader"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for SecurityHeader") + } + + // Simple Field (secureChannelId) + secureChannelId := uint32(m.GetSecureChannelId()) + _secureChannelIdErr := writeBuffer.WriteUint32("secureChannelId", 32, uint32((secureChannelId))) + if _secureChannelIdErr != nil { + return errors.Wrap(_secureChannelIdErr, "Error serializing 'secureChannelId' field") + } + + // Simple Field (secureTokenId) + secureTokenId := uint32(m.GetSecureTokenId()) + _secureTokenIdErr := writeBuffer.WriteUint32("secureTokenId", 32, uint32((secureTokenId))) + if _secureTokenIdErr != nil { + return errors.Wrap(_secureTokenIdErr, "Error serializing 'secureTokenId' field") + } + + if popErr := writeBuffer.PopContext("SecurityHeader"); popErr != nil { + return errors.Wrap(popErr, "Error popping for SecurityHeader") + } + return nil +} + +func (m *_SecurityHeader) isSecurityHeader() bool { + return true +} + +func (m *_SecurityHeader) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) + if err := writeBuffer.WriteSerializable(context.Background(), m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/opcua/readwrite/model/SequenceHeader.go b/plc4go/protocols/opcua/readwrite/model/SequenceHeader.go new file mode 100644 index 00000000000..f5de320ca8f --- /dev/null +++ b/plc4go/protocols/opcua/readwrite/model/SequenceHeader.go @@ -0,0 +1,200 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "context" + "fmt" + "github.com/apache/plc4x/plc4go/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// Code generated by code-generation. DO NOT EDIT. + +// SequenceHeader is the corresponding interface of SequenceHeader +type SequenceHeader interface { + fmt.Stringer + utils.LengthAware + utils.Serializable + // GetSequenceNumber returns SequenceNumber (property field) + GetSequenceNumber() int32 + // GetRequestId returns RequestId (property field) + GetRequestId() int32 +} + +// SequenceHeaderExactly can be used when we want exactly this type and not a type which fulfills SequenceHeader. +// This is useful for switch cases. +type SequenceHeaderExactly interface { + SequenceHeader + isSequenceHeader() bool +} + +// _SequenceHeader is the data-structure of this message +type _SequenceHeader struct { + SequenceNumber int32 + RequestId int32 +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_SequenceHeader) GetSequenceNumber() int32 { + return m.SequenceNumber +} + +func (m *_SequenceHeader) GetRequestId() int32 { + return m.RequestId +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewSequenceHeader factory function for _SequenceHeader +func NewSequenceHeader(sequenceNumber int32, requestId int32) *_SequenceHeader { + return &_SequenceHeader{SequenceNumber: sequenceNumber, RequestId: requestId} +} + +// Deprecated: use the interface for direct cast +func CastSequenceHeader(structType any) SequenceHeader { + if casted, ok := structType.(SequenceHeader); ok { + return casted + } + if casted, ok := structType.(*SequenceHeader); ok { + return *casted + } + return nil +} + +func (m *_SequenceHeader) GetTypeName() string { + return "SequenceHeader" +} + +func (m *_SequenceHeader) GetLengthInBits(ctx context.Context) uint16 { + lengthInBits := uint16(0) + + // Simple field (sequenceNumber) + lengthInBits += 32 + + // Simple field (requestId) + lengthInBits += 32 + + return lengthInBits +} + +func (m *_SequenceHeader) GetLengthInBytes(ctx context.Context) uint16 { + return m.GetLengthInBits(ctx) / 8 +} + +func SequenceHeaderParse(ctx context.Context, theBytes []byte) (SequenceHeader, error) { + return SequenceHeaderParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes)) +} + +func SequenceHeaderParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) (SequenceHeader, error) { + positionAware := readBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pullErr := readBuffer.PullContext("SequenceHeader"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for SequenceHeader") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Simple Field (sequenceNumber) + _sequenceNumber, _sequenceNumberErr := readBuffer.ReadInt32("sequenceNumber", 32) + if _sequenceNumberErr != nil { + return nil, errors.Wrap(_sequenceNumberErr, "Error parsing 'sequenceNumber' field of SequenceHeader") + } + sequenceNumber := _sequenceNumber + + // Simple Field (requestId) + _requestId, _requestIdErr := readBuffer.ReadInt32("requestId", 32) + if _requestIdErr != nil { + return nil, errors.Wrap(_requestIdErr, "Error parsing 'requestId' field of SequenceHeader") + } + requestId := _requestId + + if closeErr := readBuffer.CloseContext("SequenceHeader"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for SequenceHeader") + } + + // Create the instance + return &_SequenceHeader{ + SequenceNumber: sequenceNumber, + RequestId: requestId, + }, nil +} + +func (m *_SequenceHeader) Serialize() ([]byte, error) { + wb := utils.NewWriteBufferByteBased(utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes(context.Background())))) + if err := m.SerializeWithWriteBuffer(context.Background(), wb); err != nil { + return nil, err + } + return wb.GetBytes(), nil +} + +func (m *_SequenceHeader) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { + positionAware := writeBuffer + _ = positionAware + log := zerolog.Ctx(ctx) + _ = log + if pushErr := writeBuffer.PushContext("SequenceHeader"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for SequenceHeader") + } + + // Simple Field (sequenceNumber) + sequenceNumber := int32(m.GetSequenceNumber()) + _sequenceNumberErr := writeBuffer.WriteInt32("sequenceNumber", 32, int32((sequenceNumber))) + if _sequenceNumberErr != nil { + return errors.Wrap(_sequenceNumberErr, "Error serializing 'sequenceNumber' field") + } + + // Simple Field (requestId) + requestId := int32(m.GetRequestId()) + _requestIdErr := writeBuffer.WriteInt32("requestId", 32, int32((requestId))) + if _requestIdErr != nil { + return errors.Wrap(_requestIdErr, "Error serializing 'requestId' field") + } + + if popErr := writeBuffer.PopContext("SequenceHeader"); popErr != nil { + return errors.Wrap(popErr, "Error popping for SequenceHeader") + } + return nil +} + +func (m *_SequenceHeader) isSequenceHeader() bool { + return true +} + +func (m *_SequenceHeader) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) + if err := writeBuffer.WriteSerializable(context.Background(), m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +}