Skip to content

Commit

Permalink
refactor(plc4go): use generated Stringers instead of hand written ones
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Jun 13, 2023
1 parent d06433b commit 3aa6605
Show file tree
Hide file tree
Showing 74 changed files with 2,736 additions and 434 deletions.
4 changes: 2 additions & 2 deletions plc4go/internal/ads/Connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Connection struct {
requestInterceptor interceptors.RequestInterceptor
configuration model.Configuration
driverContext *DriverContext
tracer *tracer.Tracer
tracer tracer.Tracer

subscriptions map[uint32]apiModel.PlcSubscriptionHandle

Expand Down Expand Up @@ -96,7 +96,7 @@ func (m *Connection) IsTraceEnabled() bool {
return m.tracer != nil
}

func (m *Connection) GetTracer() *tracer.Tracer {
func (m *Connection) GetTracer() tracer.Tracer {
return m.tracer
}

Expand Down
4 changes: 2 additions & 2 deletions plc4go/internal/bacnetip/Connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Connection struct {
tm transactions.RequestTransactionManager

connectionId string
tracer *tracer.Tracer
tracer tracer.Tracer

log zerolog.Logger
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func (c *Connection) IsTraceEnabled() bool {
return c.tracer != nil
}

func (c *Connection) GetTracer() *tracer.Tracer {
func (c *Connection) GetTracer() tracer.Tracer {
return c.tracer
}

Expand Down
61 changes: 61 additions & 0 deletions plc4go/internal/cbus/AlphaGenerator_plc4xgen.go

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

6 changes: 1 addition & 5 deletions plc4go/internal/cbus/Configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
package cbus

import (
"fmt"
"github.com/rs/zerolog"
"reflect"
"strconv"

"github.com/pkg/errors"
)

//go:generate go run ../../tools/plc4xgenerator/gen.go -type=Configuration
type Configuration struct {
Srchk bool
Exstat bool
Expand Down Expand Up @@ -99,7 +99,3 @@ func getFromOptions(localLog zerolog.Logger, options map[string][]string, key st
}
return ""
}

func (c Configuration) String() string {
return fmt.Sprintf("%#v", c)
}
105 changes: 105 additions & 0 deletions plc4go/internal/cbus/Configuration_plc4xgen.go

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

10 changes: 9 additions & 1 deletion plc4go/internal/cbus/Configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,15 @@ func TestConfiguration_String(t *testing.T) {
MonitoredApplication1: 2,
MonitoredApplication2: 3,
},
want: "cbus.Configuration{Srchk:true, Exstat:true, Pun:true, LocalSal:true, Pcn:true, Idmon:true, Monitor:true, Smart:true, XonXoff:true, Connect:true, MonitoredApplication1:0x2, MonitoredApplication2:0x3}",
want: `
╔═Configuration═════════════════════════════════════════════════════════════════════════════════╗
║╔═srchk═╗╔═exstat╗╔═pun═══╗╔═localSal╗╔═pcn═══╗╔═idmon═╗╔═monitor╗╔═smart═╗╔═xonXoff╗╔═connect╗║
║║b1 true║║b1 true║║b1 true║║ b1 true ║║b1 true║║b1 true║║b1 true ║║b1 true║║b1 true ║║b1 true ║║
║╚═══════╝╚═══════╝╚═══════╝╚═════════╝╚═══════╝╚═══════╝╚════════╝╚═══════╝╚════════╝╚════════╝║
║╔═monitoredApplication1╗╔═monitoredApplication2╗ ║
║║ 0x02 '.' ║║ 0x03 '.' ║ ║
║╚══════════════════════╝╚══════════════════════╝ ║
╚═══════════════════════════════════════════════════════════════════════════════════════════════╝`[1:],
},
}
for _, tt := range tests {
Expand Down
44 changes: 8 additions & 36 deletions plc4go/internal/cbus/Connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package cbus

import (
"context"
"fmt"
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/tracer"
"github.com/apache/plc4x/plc4go/spi/transactions"
Expand All @@ -41,6 +40,7 @@ import (
"github.com/pkg/errors"
)

//go:generate go run ../../tools/plc4xgenerator/gen.go -type=AlphaGenerator
type AlphaGenerator struct {
currentAlpha byte
lock sync.Mutex
Expand All @@ -58,24 +58,21 @@ func (t *AlphaGenerator) getAndIncrement() byte {
return result
}

func (t *AlphaGenerator) String() string {
return fmt.Sprintf("AlphaGenerator(currentAlpha: %c)", t.currentAlpha)
}

//go:generate go run ../../tools/plc4xgenerator/gen.go -type=Connection
type Connection struct {
_default.DefaultConnection
alphaGenerator AlphaGenerator
alphaGenerator AlphaGenerator `stringer:"true"`
messageCodec *MessageCodec
subscribers []*Subscriber
tm transactions.RequestTransactionManager

configuration Configuration
driverContext DriverContext
configuration Configuration `stringer:"true"`
driverContext DriverContext `stringer:"true"`

connectionId string
tracer *tracer.Tracer
tracer tracer.Tracer

log zerolog.Logger
log zerolog.Logger `ignore:"true"`
}

func NewConnection(messageCodec *MessageCodec, configuration Configuration, driverContext DriverContext, tagHandler spi.PlcTagHandler, tm transactions.RequestTransactionManager, connectionOptions map[string][]string, _options ...options.WithOption) *Connection {
Expand Down Expand Up @@ -111,7 +108,7 @@ func (c *Connection) IsTraceEnabled() bool {
return c.tracer != nil
}

func (c *Connection) GetTracer() *tracer.Tracer {
func (c *Connection) GetTracer() tracer.Tracer {
return c.tracer
}

Expand Down Expand Up @@ -197,31 +194,6 @@ func (c *Connection) addSubscriber(subscriber *Subscriber) {
c.subscribers = append(c.subscribers, subscriber)
}

func (c *Connection) String() string {
return fmt.Sprintf(
"cbus.Connection{\n"+
"\tDefaultConnection: %s,\n"+
"\tAlphaGenerator: %s\n"+
"\tMessageCodec: %s\n"+
"\tsubscribers: %s\n"+
"\ttm: %s\n"+
"\tconfiguration: %s\n"+
"\tdriverContext: %s\n"+
"\tconnectionId: %s\n"+
"\ttracer: %s\n"+
"}",
c.DefaultConnection,
&c.alphaGenerator,
c.messageCodec,
c.subscribers,
c.tm,
c.configuration,
c.driverContext,
c.connectionId,
c.tracer,
)
}

func (c *Connection) setupConnection(ctx context.Context, ch chan plc4go.PlcConnectionConnectResult) {
cbusOptions := &c.messageCodec.cbusOptions
requestContext := &c.messageCodec.requestContext
Expand Down
Loading

0 comments on commit 3aa6605

Please sign in to comment.