OpenProtocolInterpreter icon indicating copy to clipboard operation
OpenProtocolInterpreter copied to clipboard

Not setting some properties produces invalid output

Open ekdahl opened this issue 2 years ago • 1 comments

When not setting some properties the output generated when packing to a string is invalid. The length in the header says what it should be, but the produced output is missing characters from the unset properties. For strings for example, wouldn't it be better to output a string of the correct length filled with spaces if the property has not been set? Integers could be 0, booleans could be false etc. I understand that there could be situations where it is hard to define a default value, but it would be good to know that a valid output is produced, without setting all properties.

Also, when setting string that is longer than max length, the length is not limited to the specified length.

Sample console application (but applies to many MIDs):

using OpenProtocolInterpreter;
using OpenProtocolInterpreter.Communication;

var midInterpreter = new MidInterpreter().UseAllMessages();

Console.WriteLine("'" + new Mid0002(1).Pack() + "'");
// Invalid output: '00570002001         010203'
// Message too short

var mid0002 = new Mid0002(1) { CellId = 0, ChannelId = 0, ControllerName = String.Empty };
Console.WriteLine("'" + mid0002.Pack() + "'");
// Valid output: '00570002001         010000020003                         '

mid0002 = new Mid0002(1) { CellId = 0, ChannelId = 0, ControllerName = "String that is longer than 25 characters" };
Console.WriteLine("'" + mid0002.Pack() + "'");
// Invalid output: '00720002001         010000020003String that is longer than 25 characters'
// String not limited to 25 characters, length in header not according to specification

ekdahl avatar Sep 05 '22 07:09 ekdahl

The default char for padding is always ' ', variable probably is not initialized at data fields.

Going to check it, thank you for submiting it!

Rickedb avatar Sep 05 '22 22:09 Rickedb