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));
            }
        }
Exemple #2
0
            private static IFieldDefinitionRecord BuildFieldDefinitionRecord(string name, TpsTypeCode typeCode)
            {
                var mock = new Mock <IFieldDefinitionRecord>();

                mock.Setup(m => m.Name).Returns(name);
                mock.Setup(m => m.Type).Returns(typeCode);

                return(mock.Object);
            }