/// <summary> /// Create a new Optional Field from a byte[] value /// </summary> /// <param name="typeCode">Option type</param> /// <param name="value">The value, which will be padded to 32-bits if required</param> public OptionalField(OptionTypeCode typeCode, byte[] value) { this.Code = typeCode.Value; this.Value = value; // 2 bytes for Option Code, 2 bytes for Option Value Length (without padding), variable length for Value Length (including any padding) this.Length = sizeof(short) + sizeof(short) + this.Value.GetAlignedLength(); }
/// <summary> /// Create a new Optional Field from a string value /// </summary> /// <param name="typeCode">Option type</param> /// <param name="value">The value, which will be converted to a UTF8-encoded byte array and padded to 32-bits if required</param> public OptionalField(OptionTypeCode typeCode, string value) : this(typeCode, Encoding.UTF8.GetBytes(value)) { // Do nothing }