You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2022/07/28 15:00:01 UTC
[plc4x] 02/02: refactor(cbus): removed unneeded types
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 6e5abebda652af26103410f15d06cba196b9e4ac
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jul 28 16:59:52 2022 +0200
refactor(cbus): removed unneeded types
---
plc4go/protocols/cbus/readwrite/ParserHelper.go | 4 -
plc4go/protocols/cbus/readwrite/XmlParserHelper.go | 4 -
.../protocols/cbus/readwrite/model/BridgeCount.go | 157 ---------------------
.../model/MonitoredSALShortFormBasicMode.go | 78 +++-------
.../cbus/readwrite/model/NetworkNumber.go | 157 ---------------------
.../src/main/resources/protocols/cbus/c-bus.mspec | 12 +-
6 files changed, 23 insertions(+), 389 deletions(-)
diff --git a/plc4go/protocols/cbus/readwrite/ParserHelper.go b/plc4go/protocols/cbus/readwrite/ParserHelper.go
index 76039241c..4a1e89cad 100644
--- a/plc4go/protocols/cbus/readwrite/ParserHelper.go
+++ b/plc4go/protocols/cbus/readwrite/ParserHelper.go
@@ -50,8 +50,6 @@ func (m CbusParserHelper) Parse(typeName string, arguments []string, io utils.Re
return model.HVACStartTimeParse(io)
case "HVACTemperature":
return model.HVACTemperatureParse(io)
- case "NetworkNumber":
- return model.NetworkNumberParse(io)
case "RequestTermination":
return model.RequestTerminationParse(io)
case "ReplyOrConfirmation":
@@ -76,8 +74,6 @@ func (m CbusParserHelper) Parse(typeName string, arguments []string, io utils.Re
return model.PanicStatusParse(io)
case "IdentifyReplyCommandUnitSummary":
return model.IdentifyReplyCommandUnitSummaryParse(io)
- case "BridgeCount":
- return model.BridgeCountParse(io)
case "PowerUp":
return model.PowerUpParse(io)
case "Reply":
diff --git a/plc4go/protocols/cbus/readwrite/XmlParserHelper.go b/plc4go/protocols/cbus/readwrite/XmlParserHelper.go
index 69d4d0d2b..c48a2fa3d 100644
--- a/plc4go/protocols/cbus/readwrite/XmlParserHelper.go
+++ b/plc4go/protocols/cbus/readwrite/XmlParserHelper.go
@@ -60,8 +60,6 @@ func (m CbusXmlParserHelper) Parse(typeName string, xmlString string, parserArgu
return model.HVACStartTimeParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
case "HVACTemperature":
return model.HVACTemperatureParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
- case "NetworkNumber":
- return model.NetworkNumberParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
case "RequestTermination":
return model.RequestTerminationParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
case "ReplyOrConfirmation":
@@ -87,8 +85,6 @@ func (m CbusXmlParserHelper) Parse(typeName string, xmlString string, parserArgu
return model.PanicStatusParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
case "IdentifyReplyCommandUnitSummary":
return model.IdentifyReplyCommandUnitSummaryParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
- case "BridgeCount":
- return model.BridgeCountParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
case "PowerUp":
return model.PowerUpParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
case "Reply":
diff --git a/plc4go/protocols/cbus/readwrite/model/BridgeCount.go b/plc4go/protocols/cbus/readwrite/model/BridgeCount.go
deleted file mode 100644
index 13e1fed65..000000000
--- a/plc4go/protocols/cbus/readwrite/model/BridgeCount.go
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * 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 (
- "github.com/apache/plc4x/plc4go/internal/spi/utils"
- "github.com/pkg/errors"
-)
-
-// Code generated by code-generation. DO NOT EDIT.
-
-// BridgeCount is the corresponding interface of BridgeCount
-type BridgeCount interface {
- utils.LengthAware
- utils.Serializable
- // GetCount returns Count (property field)
- GetCount() uint8
-}
-
-// BridgeCountExactly can be used when we want exactly this type and not a type which fulfills BridgeCount.
-// This is useful for switch cases.
-type BridgeCountExactly interface {
- BridgeCount
- isBridgeCount() bool
-}
-
-// _BridgeCount is the data-structure of this message
-type _BridgeCount struct {
- Count uint8
-}
-
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-/////////////////////// Accessors for property fields.
-///////////////////////
-
-func (m *_BridgeCount) GetCount() uint8 {
- return m.Count
-}
-
-///////////////////////
-///////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-
-// NewBridgeCount factory function for _BridgeCount
-func NewBridgeCount(count uint8) *_BridgeCount {
- return &_BridgeCount{Count: count}
-}
-
-// Deprecated: use the interface for direct cast
-func CastBridgeCount(structType interface{}) BridgeCount {
- if casted, ok := structType.(BridgeCount); ok {
- return casted
- }
- if casted, ok := structType.(*BridgeCount); ok {
- return *casted
- }
- return nil
-}
-
-func (m *_BridgeCount) GetTypeName() string {
- return "BridgeCount"
-}
-
-func (m *_BridgeCount) GetLengthInBits() uint16 {
- return m.GetLengthInBitsConditional(false)
-}
-
-func (m *_BridgeCount) GetLengthInBitsConditional(lastItem bool) uint16 {
- lengthInBits := uint16(0)
-
- // Simple field (count)
- lengthInBits += 8
-
- return lengthInBits
-}
-
-func (m *_BridgeCount) GetLengthInBytes() uint16 {
- return m.GetLengthInBits() / 8
-}
-
-func BridgeCountParse(readBuffer utils.ReadBuffer) (BridgeCount, error) {
- positionAware := readBuffer
- _ = positionAware
- if pullErr := readBuffer.PullContext("BridgeCount"); pullErr != nil {
- return nil, errors.Wrap(pullErr, "Error pulling for BridgeCount")
- }
- currentPos := positionAware.GetPos()
- _ = currentPos
-
- // Simple Field (count)
- _count, _countErr := readBuffer.ReadUint8("count", 8)
- if _countErr != nil {
- return nil, errors.Wrap(_countErr, "Error parsing 'count' field of BridgeCount")
- }
- count := _count
-
- if closeErr := readBuffer.CloseContext("BridgeCount"); closeErr != nil {
- return nil, errors.Wrap(closeErr, "Error closing for BridgeCount")
- }
-
- // Create the instance
- return NewBridgeCount(count), nil
-}
-
-func (m *_BridgeCount) Serialize(writeBuffer utils.WriteBuffer) error {
- positionAware := writeBuffer
- _ = positionAware
- if pushErr := writeBuffer.PushContext("BridgeCount"); pushErr != nil {
- return errors.Wrap(pushErr, "Error pushing for BridgeCount")
- }
-
- // Simple Field (count)
- count := uint8(m.GetCount())
- _countErr := writeBuffer.WriteUint8("count", 8, (count))
- if _countErr != nil {
- return errors.Wrap(_countErr, "Error serializing 'count' field")
- }
-
- if popErr := writeBuffer.PopContext("BridgeCount"); popErr != nil {
- return errors.Wrap(popErr, "Error popping for BridgeCount")
- }
- return nil
-}
-
-func (m *_BridgeCount) isBridgeCount() bool {
- return true
-}
-
-func (m *_BridgeCount) String() string {
- if m == nil {
- return "<nil>"
- }
- writeBuffer := utils.NewBoxedWriteBufferWithOptions(true, true)
- if err := writeBuffer.WriteSerializable(m); err != nil {
- return err.Error()
- }
- return writeBuffer.GetBox().String()
-}
diff --git a/plc4go/protocols/cbus/readwrite/model/MonitoredSALShortFormBasicMode.go b/plc4go/protocols/cbus/readwrite/model/MonitoredSALShortFormBasicMode.go
index 1d617134f..fd35ab3d3 100644
--- a/plc4go/protocols/cbus/readwrite/model/MonitoredSALShortFormBasicMode.go
+++ b/plc4go/protocols/cbus/readwrite/model/MonitoredSALShortFormBasicMode.go
@@ -36,9 +36,9 @@ type MonitoredSALShortFormBasicMode interface {
// GetCounts returns Counts (property field)
GetCounts() byte
// GetBridgeCount returns BridgeCount (property field)
- GetBridgeCount() BridgeCount
+ GetBridgeCount() *uint8
// GetNetworkNumber returns NetworkNumber (property field)
- GetNetworkNumber() NetworkNumber
+ GetNetworkNumber() *uint8
// GetNoCounts returns NoCounts (property field)
GetNoCounts() *byte
// GetApplication returns Application (property field)
@@ -58,8 +58,8 @@ type MonitoredSALShortFormBasicModeExactly interface {
type _MonitoredSALShortFormBasicMode struct {
*_MonitoredSAL
Counts byte
- BridgeCount BridgeCount
- NetworkNumber NetworkNumber
+ BridgeCount *uint8
+ NetworkNumber *uint8
NoCounts *byte
Application ApplicationIdContainer
SalData SALData
@@ -92,11 +92,11 @@ func (m *_MonitoredSALShortFormBasicMode) GetCounts() byte {
return m.Counts
}
-func (m *_MonitoredSALShortFormBasicMode) GetBridgeCount() BridgeCount {
+func (m *_MonitoredSALShortFormBasicMode) GetBridgeCount() *uint8 {
return m.BridgeCount
}
-func (m *_MonitoredSALShortFormBasicMode) GetNetworkNumber() NetworkNumber {
+func (m *_MonitoredSALShortFormBasicMode) GetNetworkNumber() *uint8 {
return m.NetworkNumber
}
@@ -118,7 +118,7 @@ func (m *_MonitoredSALShortFormBasicMode) GetSalData() SALData {
///////////////////////////////////////////////////////////
// NewMonitoredSALShortFormBasicMode factory function for _MonitoredSALShortFormBasicMode
-func NewMonitoredSALShortFormBasicMode(counts byte, bridgeCount BridgeCount, networkNumber NetworkNumber, noCounts *byte, application ApplicationIdContainer, salData SALData, salType byte, cBusOptions CBusOptions) *_MonitoredSALShortFormBasicMode {
+func NewMonitoredSALShortFormBasicMode(counts byte, bridgeCount *uint8, networkNumber *uint8, noCounts *byte, application ApplicationIdContainer, salData SALData, salType byte, cBusOptions CBusOptions) *_MonitoredSALShortFormBasicMode {
_result := &_MonitoredSALShortFormBasicMode{
Counts: counts,
BridgeCount: bridgeCount,
@@ -156,12 +156,12 @@ func (m *_MonitoredSALShortFormBasicMode) GetLengthInBitsConditional(lastItem bo
// Optional Field (bridgeCount)
if m.BridgeCount != nil {
- lengthInBits += m.BridgeCount.GetLengthInBits()
+ lengthInBits += 8
}
// Optional Field (networkNumber)
if m.NetworkNumber != nil {
- lengthInBits += m.NetworkNumber.GetLengthInBits()
+ lengthInBits += 8
}
// Optional Field (noCounts)
@@ -203,47 +203,23 @@ func MonitoredSALShortFormBasicModeParse(readBuffer utils.ReadBuffer, cBusOption
readBuffer.Reset(currentPos)
// Optional Field (bridgeCount) (Can be skipped, if a given expression evaluates to false)
- var bridgeCount BridgeCount = nil
+ var bridgeCount *uint8 = nil
if bool((counts) != (0x00)) {
- currentPos = positionAware.GetPos()
- if pullErr := readBuffer.PullContext("bridgeCount"); pullErr != nil {
- return nil, errors.Wrap(pullErr, "Error pulling for bridgeCount")
- }
- _val, _err := BridgeCountParse(readBuffer)
- switch {
- case errors.Is(_err, utils.ParseAssertError{}) || errors.Is(_err, io.EOF):
- log.Debug().Err(_err).Msg("Resetting position because optional threw an error")
- readBuffer.Reset(currentPos)
- case _err != nil:
+ _val, _err := readBuffer.ReadUint8("bridgeCount", 8)
+ if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'bridgeCount' field of MonitoredSALShortFormBasicMode")
- default:
- bridgeCount = _val.(BridgeCount)
- if closeErr := readBuffer.CloseContext("bridgeCount"); closeErr != nil {
- return nil, errors.Wrap(closeErr, "Error closing for bridgeCount")
- }
}
+ bridgeCount = &_val
}
// Optional Field (networkNumber) (Can be skipped, if a given expression evaluates to false)
- var networkNumber NetworkNumber = nil
+ var networkNumber *uint8 = nil
if bool((counts) != (0x00)) {
- currentPos = positionAware.GetPos()
- if pullErr := readBuffer.PullContext("networkNumber"); pullErr != nil {
- return nil, errors.Wrap(pullErr, "Error pulling for networkNumber")
- }
- _val, _err := NetworkNumberParse(readBuffer)
- switch {
- case errors.Is(_err, utils.ParseAssertError{}) || errors.Is(_err, io.EOF):
- log.Debug().Err(_err).Msg("Resetting position because optional threw an error")
- readBuffer.Reset(currentPos)
- case _err != nil:
+ _val, _err := readBuffer.ReadUint8("networkNumber", 8)
+ if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'networkNumber' field of MonitoredSALShortFormBasicMode")
- default:
- networkNumber = _val.(NetworkNumber)
- if closeErr := readBuffer.CloseContext("networkNumber"); closeErr != nil {
- return nil, errors.Wrap(closeErr, "Error closing for networkNumber")
- }
}
+ networkNumber = &_val
}
// Optional Field (noCounts) (Can be skipped, if a given expression evaluates to false)
@@ -320,32 +296,20 @@ func (m *_MonitoredSALShortFormBasicMode) Serialize(writeBuffer utils.WriteBuffe
}
// Optional Field (bridgeCount) (Can be skipped, if the value is null)
- var bridgeCount BridgeCount = nil
+ var bridgeCount *uint8 = nil
if m.GetBridgeCount() != nil {
- if pushErr := writeBuffer.PushContext("bridgeCount"); pushErr != nil {
- return errors.Wrap(pushErr, "Error pushing for bridgeCount")
- }
bridgeCount = m.GetBridgeCount()
- _bridgeCountErr := writeBuffer.WriteSerializable(bridgeCount)
- if popErr := writeBuffer.PopContext("bridgeCount"); popErr != nil {
- return errors.Wrap(popErr, "Error popping for bridgeCount")
- }
+ _bridgeCountErr := writeBuffer.WriteUint8("bridgeCount", 8, *(bridgeCount))
if _bridgeCountErr != nil {
return errors.Wrap(_bridgeCountErr, "Error serializing 'bridgeCount' field")
}
}
// Optional Field (networkNumber) (Can be skipped, if the value is null)
- var networkNumber NetworkNumber = nil
+ var networkNumber *uint8 = nil
if m.GetNetworkNumber() != nil {
- if pushErr := writeBuffer.PushContext("networkNumber"); pushErr != nil {
- return errors.Wrap(pushErr, "Error pushing for networkNumber")
- }
networkNumber = m.GetNetworkNumber()
- _networkNumberErr := writeBuffer.WriteSerializable(networkNumber)
- if popErr := writeBuffer.PopContext("networkNumber"); popErr != nil {
- return errors.Wrap(popErr, "Error popping for networkNumber")
- }
+ _networkNumberErr := writeBuffer.WriteUint8("networkNumber", 8, *(networkNumber))
if _networkNumberErr != nil {
return errors.Wrap(_networkNumberErr, "Error serializing 'networkNumber' field")
}
diff --git a/plc4go/protocols/cbus/readwrite/model/NetworkNumber.go b/plc4go/protocols/cbus/readwrite/model/NetworkNumber.go
deleted file mode 100644
index 557be50b4..000000000
--- a/plc4go/protocols/cbus/readwrite/model/NetworkNumber.go
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * 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 (
- "github.com/apache/plc4x/plc4go/internal/spi/utils"
- "github.com/pkg/errors"
-)
-
-// Code generated by code-generation. DO NOT EDIT.
-
-// NetworkNumber is the corresponding interface of NetworkNumber
-type NetworkNumber interface {
- utils.LengthAware
- utils.Serializable
- // GetNumber returns Number (property field)
- GetNumber() uint8
-}
-
-// NetworkNumberExactly can be used when we want exactly this type and not a type which fulfills NetworkNumber.
-// This is useful for switch cases.
-type NetworkNumberExactly interface {
- NetworkNumber
- isNetworkNumber() bool
-}
-
-// _NetworkNumber is the data-structure of this message
-type _NetworkNumber struct {
- Number uint8
-}
-
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-/////////////////////// Accessors for property fields.
-///////////////////////
-
-func (m *_NetworkNumber) GetNumber() uint8 {
- return m.Number
-}
-
-///////////////////////
-///////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-
-// NewNetworkNumber factory function for _NetworkNumber
-func NewNetworkNumber(number uint8) *_NetworkNumber {
- return &_NetworkNumber{Number: number}
-}
-
-// Deprecated: use the interface for direct cast
-func CastNetworkNumber(structType interface{}) NetworkNumber {
- if casted, ok := structType.(NetworkNumber); ok {
- return casted
- }
- if casted, ok := structType.(*NetworkNumber); ok {
- return *casted
- }
- return nil
-}
-
-func (m *_NetworkNumber) GetTypeName() string {
- return "NetworkNumber"
-}
-
-func (m *_NetworkNumber) GetLengthInBits() uint16 {
- return m.GetLengthInBitsConditional(false)
-}
-
-func (m *_NetworkNumber) GetLengthInBitsConditional(lastItem bool) uint16 {
- lengthInBits := uint16(0)
-
- // Simple field (number)
- lengthInBits += 8
-
- return lengthInBits
-}
-
-func (m *_NetworkNumber) GetLengthInBytes() uint16 {
- return m.GetLengthInBits() / 8
-}
-
-func NetworkNumberParse(readBuffer utils.ReadBuffer) (NetworkNumber, error) {
- positionAware := readBuffer
- _ = positionAware
- if pullErr := readBuffer.PullContext("NetworkNumber"); pullErr != nil {
- return nil, errors.Wrap(pullErr, "Error pulling for NetworkNumber")
- }
- currentPos := positionAware.GetPos()
- _ = currentPos
-
- // Simple Field (number)
- _number, _numberErr := readBuffer.ReadUint8("number", 8)
- if _numberErr != nil {
- return nil, errors.Wrap(_numberErr, "Error parsing 'number' field of NetworkNumber")
- }
- number := _number
-
- if closeErr := readBuffer.CloseContext("NetworkNumber"); closeErr != nil {
- return nil, errors.Wrap(closeErr, "Error closing for NetworkNumber")
- }
-
- // Create the instance
- return NewNetworkNumber(number), nil
-}
-
-func (m *_NetworkNumber) Serialize(writeBuffer utils.WriteBuffer) error {
- positionAware := writeBuffer
- _ = positionAware
- if pushErr := writeBuffer.PushContext("NetworkNumber"); pushErr != nil {
- return errors.Wrap(pushErr, "Error pushing for NetworkNumber")
- }
-
- // Simple Field (number)
- number := uint8(m.GetNumber())
- _numberErr := writeBuffer.WriteUint8("number", 8, (number))
- if _numberErr != nil {
- return errors.Wrap(_numberErr, "Error serializing 'number' field")
- }
-
- if popErr := writeBuffer.PopContext("NetworkNumber"); popErr != nil {
- return errors.Wrap(popErr, "Error popping for NetworkNumber")
- }
- return nil
-}
-
-func (m *_NetworkNumber) isNetworkNumber() bool {
- return true
-}
-
-func (m *_NetworkNumber) String() string {
- if m == nil {
- return "<nil>"
- }
- writeBuffer := utils.NewBoxedWriteBufferWithOptions(true, true)
- if err := writeBuffer.WriteSerializable(m); err != nil {
- return err.Error()
- }
- return writeBuffer.GetBox().String()
-}
diff --git a/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec b/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec
index 2b27f891a..74b4ba741 100644
--- a/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec
+++ b/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec
@@ -1434,14 +1434,6 @@
[simple CALData('requestContext') calData ]
]
-[type BridgeCount
- [simple uint 8 count]
-]
-
-[type NetworkNumber
- [simple uint 8 number]
-]
-
[type MonitoredSAL(CBusOptions cBusOptions)
[peek byte salType ]
[typeSwitch salType
@@ -1460,8 +1452,8 @@
]
[* *ShortFormBasicMode
[peek byte counts ]
- [optional BridgeCount bridgeCount 'counts != 0x00' ]
- [optional NetworkNumber networkNumber 'counts != 0x00' ]
+ [optional uint 8 bridgeCount 'counts != 0x00' ]
+ [optional uint 8 networkNumber 'counts != 0x00' ]
[optional byte noCounts 'counts == 0x00' ] // TODO: add validation that this is 0x00 when no bridge and network number are set
[simple ApplicationIdContainer application ]
[optional SALData('application.applicationId') salData ]