Beispiel #1
0
        /// <summary>
        /// Insert bit in the TLV format into the message.
        /// </summary>
        /// <param name="bit">The bit to be added.</param>
        /// <param name="tag">The tag code.</param>
        /// <param name="length">The length of the content.</param>
        /// <param name="value">The content of the tag.</param>
        public void AddTLV(short bit, string tag, string length, string value, DataType type = DataType.N, string valuePrefix = "", string valueSufix = "")
        {
            var size          = Convert.ToInt32(length) - valuePrefix.Length - valueSufix.Length;
            var layout        = new FieldLayout(size, FieldType.FIX, type);
            var valueToAppend = tag + length + valuePrefix + Fill(layout, value) + valueSufix;

            if (_fields.ContainsKey(bit))
            {
                _fields[bit] += valueToAppend;
            }
            else
            {
                _fields.Add(bit, valueToAppend);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Fill the content accordding to the datatype and size.
        /// </summary>
        /// <param name="field">The layout of the field.</param>
        /// <param name="value">The value to fill.</param>
        /// <returns>The content filled.</returns>
        private string Fill(FieldLayout field, string value)
        {
            switch (field.DataType)
            {
            case DataType.N:
                value = string.Join("", value.Where(char.IsDigit));
                value = value.PadLeft(field.Size.Value, '0');
                break;

            case DataType.A:
            case DataType.AN:
                value = value.PadRight(field.Size.Value, ' ');
                break;

            default:
                break;
            }

            return(value);
        }