-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Description
I'm having a problem where i set a field to be 6 and on file is written with 5
Here's the defenition:
/// <summary>
/// Gets the size of the printer model
/// </summary>
[FieldOrder(3)]
[FieldEndianness(Endianness.Big)]
public uint PrinterModelSize { get; set; } = 6;
/// <summary>
/// Gets the printer model
/// </summary>
[FieldOrder(4)]
[FieldLength(nameof(PrinterModelSize))]
[SerializeAs(SerializedType.TerminatedString)]
public string PrinterModel
{
get => _printerModel;
set
{
_printerModel = value;
PrinterModelSize = string.IsNullOrEmpty(value) ? 0 : (uint)value.Length+1;
}
}
I place a breakpoint on both PrinterModelSize = string.IsNullOrEmpty(value) ? 0 : (uint)value.Length+1; and public uint PrinterModelSize { get; set; } = 6; Both shows 6 with a value of "CL-89" which is correct since it have a null terminated char (00)
When the file got written that field turn into 5. Does it redefine the value when serializing due the link with [FieldLength(nameof(PrinterModelSize))] ? If so is there a way to overcome this?
EDIT 1:
I added to attribute [FieldLength(nameof(PrinterModelSize), BindingMode = BindingMode.OneWay)]
, that way the size become 6 but string still not null terminated (no zero appended)
Metadata
Metadata
Assignees
Labels
No labels