Ejemplo n.º 1
0
        public TpsObject ParseField(TpsTypeCode type, int length, FieldDefinitionRecord fieldDefinitionRecord, RandomAccess rx)
        {
            if (fieldDefinitionRecord == null)
            {
                throw new ArgumentNullException(nameof(fieldDefinitionRecord));
            }

            if (rx == null)
            {
                throw new ArgumentNullException(nameof(rx));
            }

            switch (type)
            {
            case TpsTypeCode.Byte:
                AssertEqual(1, length);
                return(new TpsByte(rx));

            case TpsTypeCode.Short:
                AssertEqual(2, length);
                return(new TpsShort(rx));

            case TpsTypeCode.UShort:
                AssertEqual(2, length);
                return(new TpsUnsignedShort(rx));

            case TpsTypeCode.Date:
                return(new TpsDate(rx));

            case TpsTypeCode.Time:
                return(new TpsTime(rx));

            case TpsTypeCode.Long:
                AssertEqual(4, length);
                return(new TpsLong(rx));

            case TpsTypeCode.ULong:
                AssertEqual(4, length);
                return(new TpsUnsignedLong(rx));

            case TpsTypeCode.SReal:
                AssertEqual(4, length);
                return(new TpsFloat(rx));

            case TpsTypeCode.Real:
                AssertEqual(8, length);
                return(new TpsDouble(rx));

            case TpsTypeCode.Decimal:
                return(new TpsDecimal(rx, length, fieldDefinitionRecord.BcdDigitsAfterDecimalPoint));

            case TpsTypeCode.String:
                return(new TpsString(rx, length, Encoding));

            case TpsTypeCode.CString:
                return(new TpsCString(rx, Encoding));

            case TpsTypeCode.PString:
                return(new TpsPString(rx, Encoding));

            case TpsTypeCode.Group:
                return(new TpsGroup(rx, length));

            default:
                throw new ArgumentException($"Unsupported type {type} ({length})", nameof(type));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Checks to see if this field fits in the given group field.
 /// </summary>
 /// <param name="group">The group field to check.</param>
 /// <returns></returns>
 public bool IsInGroup(FieldDefinitionRecord group) =>
 (group.Offset <= Offset) &&
 ((group.Offset + group.Length) >= (Offset + Length));