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 2023/05/17 12:05:13 UTC

[plc4x] 02/04: refactor(plc4go/spi): cleanup unused 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 794183a15deaad0d6baa4ac8142da082a441edf8
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed May 17 13:56:31 2023 +0200

    refactor(plc4go/spi): cleanup unused types
---
 .../model/DefaultPlcSubscriptionRequestResult.go   |  45 ---------
 ...DefaultPlcSubscriptionRequestResult_plc4xgen.go | 101 ---------------------
 plc4go/spi/model/DefaultPlcTagRequest.go           |   7 +-
 plc4go/spi/model/DefaultPlcWriteRequest.go         |   1 +
 plc4go/spi/model/DefaultPlcWriteResponse.go        |   1 +
 plc4go/spi/model/render_test.go                    |   1 -
 6 files changed, 6 insertions(+), 150 deletions(-)

diff --git a/plc4go/spi/model/DefaultPlcSubscriptionRequestResult.go b/plc4go/spi/model/DefaultPlcSubscriptionRequestResult.go
deleted file mode 100644
index 71a3393e5e..0000000000
--- a/plc4go/spi/model/DefaultPlcSubscriptionRequestResult.go
+++ /dev/null
@@ -1,45 +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 apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
-
-//go:generate go run ../../tools/plc4xgenerator/gen.go -type=DefaultPlcSubscriptionRequestResult
-type DefaultPlcSubscriptionRequestResult struct {
-	Request  apiModel.PlcSubscriptionRequest
-	Response apiModel.PlcSubscriptionResponse
-	Err      error
-}
-
-func NewDefaultPlcSubscriptionRequestResult(Request apiModel.PlcSubscriptionRequest, Response apiModel.PlcSubscriptionResponse, Err error) apiModel.PlcSubscriptionRequestResult {
-	return &DefaultPlcSubscriptionRequestResult{Request, Response, Err}
-}
-
-func (d *DefaultPlcSubscriptionRequestResult) GetRequest() apiModel.PlcSubscriptionRequest {
-	return d.Request
-}
-
-func (d *DefaultPlcSubscriptionRequestResult) GetResponse() apiModel.PlcSubscriptionResponse {
-	return d.Response
-}
-
-func (d *DefaultPlcSubscriptionRequestResult) GetErr() error {
-	return d.Err
-}
diff --git a/plc4go/spi/model/DefaultPlcSubscriptionRequestResult_plc4xgen.go b/plc4go/spi/model/DefaultPlcSubscriptionRequestResult_plc4xgen.go
deleted file mode 100644
index dd04d7bb9f..0000000000
--- a/plc4go/spi/model/DefaultPlcSubscriptionRequestResult_plc4xgen.go
+++ /dev/null
@@ -1,101 +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.
- */
-
-// Code generated by "plc4xgenerator -type=DefaultPlcSubscriptionRequestResult"; DO NOT EDIT.
-
-package model
-
-import (
-	"context"
-	"encoding/binary"
-	"fmt"
-	"github.com/apache/plc4x/plc4go/spi/utils"
-)
-
-var _ = fmt.Printf
-
-func (d *DefaultPlcSubscriptionRequestResult) Serialize() ([]byte, error) {
-	wb := utils.NewWriteBufferByteBased(utils.WithByteOrderForByteBasedBuffer(binary.BigEndian))
-	if err := d.SerializeWithWriteBuffer(context.Background(), wb); err != nil {
-		return nil, err
-	}
-	return wb.GetBytes(), nil
-}
-
-func (d *DefaultPlcSubscriptionRequestResult) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error {
-	if err := writeBuffer.PushContext("PlcSubscriptionRequestResult"); err != nil {
-		return err
-	}
-
-	if d.Request != nil {
-		if serializableField, ok := d.Request.(utils.Serializable); ok {
-			if err := writeBuffer.PushContext("request"); err != nil {
-				return err
-			}
-			if err := serializableField.SerializeWithWriteBuffer(ctx, writeBuffer); err != nil {
-				return err
-			}
-			if err := writeBuffer.PopContext("request"); err != nil {
-				return err
-			}
-		} else {
-			stringValue := fmt.Sprintf("%v", d.Request)
-			if err := writeBuffer.WriteString("request", uint32(len(stringValue)*8), "UTF-8", stringValue); err != nil {
-				return err
-			}
-		}
-	}
-
-	if d.Response != nil {
-		if serializableField, ok := d.Response.(utils.Serializable); ok {
-			if err := writeBuffer.PushContext("response"); err != nil {
-				return err
-			}
-			if err := serializableField.SerializeWithWriteBuffer(ctx, writeBuffer); err != nil {
-				return err
-			}
-			if err := writeBuffer.PopContext("response"); err != nil {
-				return err
-			}
-		} else {
-			stringValue := fmt.Sprintf("%v", d.Response)
-			if err := writeBuffer.WriteString("response", uint32(len(stringValue)*8), "UTF-8", stringValue); err != nil {
-				return err
-			}
-		}
-	}
-
-	if d.Err != nil {
-		if err := writeBuffer.WriteString("err", uint32(len(d.Err.Error())*8), "UTF-8", d.Err.Error()); err != nil {
-			return err
-		}
-	}
-	if err := writeBuffer.PopContext("PlcSubscriptionRequestResult"); err != nil {
-		return err
-	}
-	return nil
-}
-
-func (d *DefaultPlcSubscriptionRequestResult) String() string {
-	writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true)
-	if err := writeBuffer.WriteSerializable(context.Background(), d); err != nil {
-		return err.Error()
-	}
-	return writeBuffer.GetBox().String()
-}
diff --git a/plc4go/spi/model/DefaultPlcTagRequest.go b/plc4go/spi/model/DefaultPlcTagRequest.go
index d5c5654814..da56bd6fa0 100644
--- a/plc4go/spi/model/DefaultPlcTagRequest.go
+++ b/plc4go/spi/model/DefaultPlcTagRequest.go
@@ -42,8 +42,9 @@ func (d *DefaultPlcTagRequest) GetTagNames() []string {
 }
 
 func (d *DefaultPlcTagRequest) GetTag(name string) apiModel.PlcTag {
-	if tag, ok := d.tags[name]; ok {
-		return tag
+	tag, ok := d.tags[name]
+	if !ok {
+		return nil
 	}
-	return nil
+	return tag
 }
diff --git a/plc4go/spi/model/DefaultPlcWriteRequest.go b/plc4go/spi/model/DefaultPlcWriteRequest.go
index f065fc5764..35e114f300 100644
--- a/plc4go/spi/model/DefaultPlcWriteRequest.go
+++ b/plc4go/spi/model/DefaultPlcWriteRequest.go
@@ -194,5 +194,6 @@ func (d *DefaultPlcWriteRequest) GetWriteRequestInterceptor() interceptors.Write
 }
 
 func (d *DefaultPlcWriteRequest) GetValue(name string) apiValues.PlcValue {
+	// TODO: guard
 	return d.values[name]
 }
diff --git a/plc4go/spi/model/DefaultPlcWriteResponse.go b/plc4go/spi/model/DefaultPlcWriteResponse.go
index 5bf7e3fd7b..2198cdd648 100644
--- a/plc4go/spi/model/DefaultPlcWriteResponse.go
+++ b/plc4go/spi/model/DefaultPlcWriteResponse.go
@@ -60,5 +60,6 @@ func (d *DefaultPlcWriteResponse) GetRequest() apiModel.PlcWriteRequest {
 }
 
 func (d *DefaultPlcWriteResponse) GetResponseCode(name string) apiModel.PlcResponseCode {
+	// TODO: guard
 	return d.responseCodes[name]
 }
diff --git a/plc4go/spi/model/render_test.go b/plc4go/spi/model/render_test.go
index 4d6eb82895..e6987e58f4 100644
--- a/plc4go/spi/model/render_test.go
+++ b/plc4go/spi/model/render_test.go
@@ -55,7 +55,6 @@ func TestRenderTest(t *testing.T) {
 		&DefaultPlcSubscriptionEventItem{},
 		&DefaultPlcSubscriptionHandle{},
 		&DefaultPlcSubscriptionRequest{DefaultPlcTagRequest: NewDefaultPlcTagRequest(nil, nil)},
-		&DefaultPlcSubscriptionRequestResult{},
 		&DefaultPlcSubscriptionResponse{},
 		&DefaultPlcSubscriptionResponseItem{},
 		&DefaultPlcTagRequest{},