Skip to content

Commit

Permalink
refactor(plc4go): replace utils.Min/Max with builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Jul 26, 2024
1 parent 532decb commit bebe9e3
Show file tree
Hide file tree
Showing 213 changed files with 1,268 additions and 1,466 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -837,13 +837,13 @@ func ${type.name}ParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffe
<#-- If this is a count array, we can directly initialize an array with the given size -->
<#if field.isCountArrayField()>
// Count array
${arrayField.name} := make(${helper.getLanguageTypeNameForField(field)}, utils.Max(${helper.toIntegerParseExpression(arrayField, 16, arrayField.loopExpression, parserArguments)}, 0))
${arrayField.name} := make(${helper.getLanguageTypeNameForField(field)}, max(${helper.toIntegerParseExpression(arrayField, 16, arrayField.loopExpression, parserArguments)}, 0))
// This happens when the size is set conditional to 0
if len(${arrayField.name}) == 0 {
${arrayField.name} = nil
}
{
_numItems := uint16(utils.Max(${helper.toIntegerParseExpression(arrayField, 16, arrayField.loopExpression, parserArguments)}, 0))
_numItems := uint16(max(${helper.toIntegerParseExpression(arrayField, 16, arrayField.loopExpression, parserArguments)}, 0))
for _curItem := uint16(0); _curItem < _numItems; _curItem++ {
arrayCtx := utils.CreateArrayContext(ctx, int(_numItems), int(_curItem))
<#-- TODO: find a way to do this nicer -->
Expand Down
3 changes: 1 addition & 2 deletions plc4go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

module github.com/apache/plc4x/plc4go

go 1.20
go 1.21

require (
github.com/IBM/netaddr v1.5.0
Expand All @@ -36,7 +36,6 @@ require (
github.com/stretchr/testify v1.9.0
github.com/subchen/go-xmldom v1.1.2
github.com/viney-shih/go-lock v1.1.2
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/net v0.27.0
golang.org/x/text v0.16.0
golang.org/x/tools v0.23.0
Expand Down
2 changes: 0 additions & 2 deletions plc4go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ github.com/viney-shih/go-lock v1.1.2 h1:3TdGTiHZCPqBdTvFbQZQN/TRZzKF3KWw2rFEyKz3
github.com/viney-shih/go-lock v1.1.2/go.mod h1:Yijm78Ljteb3kRiJrbLAxVntkUukGu5uzSxq/xV7OO8=
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 h1:gga7acRE695APm9hlsSMoOoE65U4/TcqNj90mc69Rlg=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
Expand Down
9 changes: 4 additions & 5 deletions plc4go/internal/bacnetip/ApplicationLayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"time"

readWriteModel "github.com/apache/plc4x/plc4go/protocols/bacnetip/readwrite/model"
"github.com/apache/plc4x/plc4go/spi/utils"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)
Expand Down Expand Up @@ -471,7 +470,7 @@ func (c *ClientSSM) Indication(apdu _PDU) error {
// if the max npdu length of the server isn't known, assume that it is the same as the max apdu length accepted
c.segmentSize = uint(c.maxApduLengthAccepted.NumberOfOctets())
} else {
c.segmentSize = utils.Min(*c.deviceInfo.MaximumNpduLength, uint(c.maxApduLengthAccepted.NumberOfOctets()))
c.segmentSize = min(*c.deviceInfo.MaximumNpduLength, uint(c.maxApduLengthAccepted.NumberOfOctets()))
}
log.Debug().Uint("segmentSize", c.segmentSize).Msg("segment size")

Expand Down Expand Up @@ -689,7 +688,7 @@ func (c *ClientSSM) segmentedRequest(apdu _PDU) error {
}

// minimum of what the server is proposing and this client proposes
minWindowSize := utils.Min(*_apdu.GetProposedWindowSize(), c.ssmSAP.GetProposedWindowSize())
minWindowSize := min(*_apdu.GetProposedWindowSize(), c.ssmSAP.GetProposedWindowSize())
c.actualWindowSize = &minWindowSize
c.lastSequenceNumber = 0
c.initialSequenceNumber = 0
Expand Down Expand Up @@ -1112,7 +1111,7 @@ func (s *ServerSSM) Confirmation(apdu _PDU) error {
if s.deviceInfo == nil || s.deviceInfo.MaximumNpduLength == nil {
s.segmentSize = uint(s.maxApduLengthAccepted.NumberOfOctets())
} else {
s.segmentSize = utils.Min(*s.deviceInfo.MaximumNpduLength, uint(s.maxApduLengthAccepted.NumberOfOctets()))
s.segmentSize = min(*s.deviceInfo.MaximumNpduLength, uint(s.maxApduLengthAccepted.NumberOfOctets()))
}

// compute the segment count
Expand Down Expand Up @@ -1314,7 +1313,7 @@ func (s *ServerSSM) idle(apdu _PDU) error {
// the window size is the minimum of what I would propose and what the device has proposed
proposedWindowSize := *apduConfirmedRequest.GetProposedWindowSize()
configuredWindowSize := s.ssmSAP.GetProposedWindowSize()
minWindowSize := utils.Min(proposedWindowSize, configuredWindowSize)
minWindowSize := min(proposedWindowSize, configuredWindowSize)
s.actualWindowSize = &minWindowSize
log.Debug().
Uint8("proposedWindowSize", proposedWindowSize).
Expand Down
2 changes: 1 addition & 1 deletion plc4go/internal/opcua/SecureChannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"net"
"net/url"
"regexp"
"slices"
"strconv"
"sync"
"sync/atomic"
Expand All @@ -42,7 +43,6 @@ import (
"github.com/dchest/uniuri"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"golang.org/x/exp/slices"
)

const (
Expand Down
12 changes: 7 additions & 5 deletions plc4go/internal/opcua/SubscriptionHandle.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ package opcua
import (
"context"
"encoding/binary"
"slices"
"strconv"
"sync"
"sync/atomic"
"time"

apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
readWriteModel "github.com/apache/plc4x/plc4go/protocols/opcua/readwrite/model"
spiModel "github.com/apache/plc4x/plc4go/spi/model"

"github.com/apache/plc4x/plc4go/spi/utils"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"golang.org/x/exp/slices"
"strconv"
"sync"
"sync/atomic"
"time"
)

type SubscriptionHandle struct {
Expand Down

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

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

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

8 changes: 4 additions & 4 deletions plc4go/protocols/ads/readwrite/model/AdsDataTypeTableEntry.go

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

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

4 changes: 2 additions & 2 deletions plc4go/protocols/ads/readwrite/model/AdsReadWriteRequest.go

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

4 changes: 2 additions & 2 deletions plc4go/protocols/ads/readwrite/model/AdsStampHeader.go

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

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

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

Loading

0 comments on commit bebe9e3

Please sign in to comment.