Menu

#16 Marking.Characters in C#

open
nobody
None
5
2012-10-30
2011-12-15
Anonymous
No

In the C# source, the OpenDis.Dis1998.Marking class has a read/write Characters property. If the value is set to something that is not an 11-byte array, the object is invalid. If it is then marshalled to an output stream, the stream may be the wrong length.

Could this be addressed? Some possible ways I can think of include:

  1. Validate and throw an exception if the specified value is not an 11-byte array
  2. Accept any array, but truncate long ones and pad short ones so the private field is always 11 bytes long
  3. Add another property of type string and use the value to set the characters using Encoding.ASCII.GetBytes(value) and truncating/padding as required. For example:
    public string CharacterString
    {
    get { return Encoding.ASCII.GetString(Characters); }
    set { Characters = Encoding.ASCII.GetBytes(value).Concat(Enumerable.Repeat((byte) 0, 11)).Take(11).ToArray(); } // Ensures array is always 11 bytes long
    }

Discussion

MongoDB Logo MongoDB