Skip to content

Commit 02c7c06

Browse files
committed
fix(plc4go): unbreak plc4xGenerator on bacnetip DriverContext
Phase-1's DriverContext introduced the first non-pointer `model.*` enum fields used directly as struct members. plc4xGenerator's serializableFieldTemplate emits `if x != nil` for any SelectorExpr field, which is valid for pointer/interface fields but invalid Go for value-typed enums like MaxApduLengthAccepted / BACnetSegmentation / MaxSegmentsAccepted. CI's regenerated DriverContext_plc4xgen.go therefore failed to compile, breaking the mockery step. Mark the three enum fields with `stringer:"true"` so the generator calls their generated `.String()` instead of the SelectorExpr template. Mirrors how knxnetip's KnxMedium and opcua's UserTokenType are tagged. The enum values now appear by name in debug output instead of being hidden. Also check in the generated Configuration_plc4xgen.go and DriverContext_plc4xgen.go alongside MessageCodec_plc4xgen.go and Subscriber_plc4xgen.go (cbus and opcua track theirs too).
1 parent a6f6312 commit 02c7c06

12 files changed

Lines changed: 610 additions & 28 deletions

plc4go/internal/bacnetip/Configuration_plc4xgen.go

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plc4go/internal/bacnetip/DriverContext.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ type DriverContext struct {
3434
// maxApduLengthAccepted is the Configuration.MaxApduLengthAccepted byte count
3535
// translated to its BACnet enum value (used in IAm responses and confirmed
3636
// requests). E.g. 1476 → MaxApduLengthAccepted_NUM_OCTETS_1476.
37-
maxApduLengthAccepted model.MaxApduLengthAccepted
37+
maxApduLengthAccepted model.MaxApduLengthAccepted `stringer:"true"`
3838

3939
// segmentation is Configuration.SegmentationSupported translated to its
4040
// BACnet enum. Defaults to SEGMENTED_BOTH for unknown strings.
41-
segmentation model.BACnetSegmentation
41+
segmentation model.BACnetSegmentation `stringer:"true"`
4242

4343
// maxSegmentsAccepted is Configuration.MaxSegmentsAccepted translated to its
4444
// BACnet enum value (e.g. 16 → NUM_SEGMENTS_16).
45-
maxSegmentsAccepted model.MaxSegmentsAccepted
45+
maxSegmentsAccepted model.MaxSegmentsAccepted `stringer:"true"`
4646

4747
awaitSetupComplete bool
4848
awaitDisconnectComplete bool

plc4go/internal/bacnetip/DriverContext_plc4xgen.go

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plc4go/internal/bacnetip/MessageCodec.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,3 @@ func (m *MessageCodec) Receive(ctx context.Context) (spi.Message, error) {
127127
// TODO: maybe we return here a not enough error error
128128
return nil, nil
129129
}
130-

plc4go/internal/bacnetip/MessageCodec_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ func (f *fakeTransportInstance) WrittenBytes() []byte {
6464
return append([]byte(nil), f.writeBuffer.Bytes()...)
6565
}
6666

67-
func (f *fakeTransportInstance) Connect(_ context.Context) error { f.connected = true; return nil }
67+
func (f *fakeTransportInstance) Connect(_ context.Context) error { f.connected = true; return nil }
6868
func (f *fakeTransportInstance) ConnectWithContext(_ context.Context) error { return f.Connect(nil) }
69-
func (f *fakeTransportInstance) Close() error { f.connected = false; return nil }
70-
func (f *fakeTransportInstance) IsConnected() bool { return f.connected }
71-
func (f *fakeTransportInstance) String() string { return "fake" }
72-
func (f *fakeTransportInstance) Reset() {}
69+
func (f *fakeTransportInstance) Close() error { f.connected = false; return nil }
70+
func (f *fakeTransportInstance) IsConnected() bool { return f.connected }
71+
func (f *fakeTransportInstance) String() string { return "fake" }
72+
func (f *fakeTransportInstance) Reset() {}
7373

7474
func (f *fakeTransportInstance) GetNumBytesAvailableInBuffer() (uint32, error) {
7575
f.mu.Lock()

plc4go/internal/bacnetip/Segmentation.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ import (
3535
// expected sequence number, returning a SegmentAck PDU the caller must transmit
3636
// after every received segment.
3737
type inboundReassembler struct {
38-
invokeId uint8
39-
expectedSeq uint8
40-
buffer []byte
41-
windowSize uint8 // actual window size we advertised in the original request
42-
moreFollows bool
43-
complete bool
38+
invokeId uint8
39+
expectedSeq uint8
40+
buffer []byte
41+
windowSize uint8 // actual window size we advertised in the original request
42+
moreFollows bool
43+
complete bool
4444
}
4545

4646
// NewInboundReassembler creates a fresh reassembler tracking the given invoke
@@ -100,13 +100,13 @@ func (r *inboundReassembler) Bytes() []byte { return r.buffer }
100100
// SendNext returns the next segment to put on the wire, then waits for the
101101
// remote SegmentAck via AcknowledgeSegment before calling SendNext again.
102102
type outboundSegmenter struct {
103-
invokeId uint8
104-
payload []byte
105-
maxSegment uint16 // bytes per segment (peer's max APDU minus header overhead)
106-
windowSize uint8
107-
nextSeq uint8
108-
cursor int // byte offset into payload
109-
done bool
103+
invokeId uint8
104+
payload []byte
105+
maxSegment uint16 // bytes per segment (peer's max APDU minus header overhead)
106+
windowSize uint8
107+
nextSeq uint8
108+
cursor int // byte offset into payload
109+
done bool
110110
}
111111

112112
// NewOutboundSegmenter prepares a segmenter for the given serialized request

plc4go/internal/bacnetip/Subscriber_plc4xgen.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plc4go/internal/bacnetip/TagHandler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ func TestTagHandler_ParseInvalidString(t *testing.T) {
9797
cases := []string{
9898
"",
9999
"garbage",
100-
"ANALOG_INPUT,1", // missing property
101-
"ANALOG_INPUT/X", // missing instance
102-
"ANALOG_INPUT,abc/X", // non-numeric instance
103-
",1/X", // missing object type
100+
"ANALOG_INPUT,1", // missing property
101+
"ANALOG_INPUT/X", // missing instance
102+
"ANALOG_INPUT,abc/X", // non-numeric instance
103+
",1/X", // missing object type
104104
}
105105
for _, c := range cases {
106106
_, err := h.ParseTag(c)

plc4go/internal/bacnetip/ValueDecoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
// - CharacterString→ PlcSTRING
4242
// - OctetString → PlcRawByteArray
4343
// - Enumerated → PlcUDINT (the raw numeric; the property identifier on
44-
// the request side determines the enum schema)
44+
// the request side determines the enum schema)
4545
// - BitString → PlcRawByteArray (packed MSB-first)
4646
// - Date → PlcDATE (year-1900 + month + day-of-month)
4747
// - Time → PlcTIME_OF_DAY

0 commit comments

Comments
 (0)