fix(plc4go/spi): preserve WithByteOrder in UpcastReaderArgs/UpcastWriterArgs#2494
Open
khalidDaoud wants to merge 1 commit intoapache:developfrom
Open
fix(plc4go/spi): preserve WithByteOrder in UpcastReaderArgs/UpcastWriterArgs#2494khalidDaoud wants to merge 1 commit intoapache:developfrom
khalidDaoud wants to merge 1 commit intoapache:developfrom
Conversation
…terArgs UpcastReaderArgs and UpcastWriterArgs wrap WithReaderArgs/WithWriterArgs into readerWriterArg structs. When the arg already implements WithReaderWriterArgs (e.g. codegen.WithByteOrder), this wrapping destroys the concrete type, causing ExtractByteOrder's type switch to fail silently. The result is that codegen.WithByteOrder(LE) passed to ReadSimpleField/WriteSimpleField has no effect — fields are read and written with the buffer's default byte order instead. Fix: check if the arg already implements WithReaderWriterArgs and pass it through unwrapped. Affects all protocols using type-level byteOrder in mspec: ADS, AB-ETH, OPC UA, IEC 60870-5-104.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UpcastReaderArgs/UpcastWriterArgsnow preserveWithReaderWriterArgsconcrete types instead of wrapping them inreaderWriterArgProblem
UpcastReaderArgswraps every arg inreaderWriterArg{arg, writerArg{}}. When the arg is already aWithReaderWriterArgs(e.g.codegen.WithByteOrder), this wrapping changes the concrete type fromwithOptionByteOrdertoreaderWriterArg.FieldCommons.ExtractByteOrderdoes a type switch onwithOptionByteOrder— which no longer matches the wrapped type. Result:ExtractByteOrderreturnsnil, andSwitchParseByteOrderIfNecessaryskips the byte order switch entirely.This means
codegen.WithByteOrder(binary.LittleEndian)passed toReadSimpleField/WriteSimpleFieldis silently ignored — fields are read/written with the buffer's default byte order.Fix
Check if the arg already implements
WithReaderWriterArgsbefore wrapping:Affected protocols
All protocols using
byteOrder='LITTLE_ENDIAN'at the type level in mspec: ADS, AB-ETH, OPC UA, IEC 60870-5-104.Test plan