예제 #1
0
        // for seq no > 0 in the Record Code only
        private long ExpectNextSeqNo(ReadArgs args)
        {
            long actualSeqNo = 0;

            while (true)
            {
                int readChar = args.ReadOne();
                int digit    = readChar - iDigit0;
                if (digit >= 0 && digit < 10)
                {
                    actualSeqNo = (actualSeqNo * 10) + digit;
                }
                else
                {
                    if (readChar == iFieldSep)
                    {
                        break;
                    }
                    else
                    {
                        throw Error.Unexpected(ErrorCode.UnexpectedChars, '0', readChar);
                    }
                }
            }

            if (actualSeqNo != args.dcRecords.Count)
            {
                throw Error.Unexpected(ErrorCode.UnexpectedSequenceNo, args.dcRecords.Count, actualSeqNo);
            }

            return(actualSeqNo);
        }
예제 #2
0
        public override void Read(ReadArgs args)
        {
            args.SetValues();
            args.CurrentSeqNo = ExpectNextSeqNo(args);

            int readChar = args.ReadOne();

            if (readChar == iRefPrefix)
            {
                args.State = ReaderInstance.Singleton;
            }
            else if (readChar == iArray)
            {
                readChar = args.ReadOne();
                if (readChar != iFieldSep)
                {
                    throw Error.Unexpected(ErrorCode.UnexpectedChars, FieldSeparator, readChar);
                }

                ArrayRecord rec = new ArrayRecord(args.CurrentSeqNo);
                args.SetupRecord(rec);
                args.Read.Read(rec);

                args.State = ReaderField.Singleton;
            }
            else if (readChar == iStringEncl)
            {
                args.State = ReaderTypeDef.Singleton;
            }
            else
            {
                throw new Error(ErrorCode.UnknownRecordType).AddData(ErrorDataKeys.Actual, readChar);
            }
        }
예제 #3
0
        public override void Read(ReadArgs args)
        {
            // read Version Record Code '0,'
            if (args.ReadOne() != iDigit0 || args.ReadOne() != iFieldSep)
            {
                throw Error.UnexpectedRecordType(RecordType.Version, RecordType.Unknown);
            }
            args.CurrentSeqNo = 0;

            // TODO - version validation ??

            VersionRecord vr = new VersionRecord(base.ReadStringStrict(args));

            args.dcRecords[args.CurrentSeqNo] = vr;
            args.Read.Read(vr);

            int readChar = args.ReadOne();

            if (readChar == iRecordSep)
            {
                args.State = ReaderNewRecord.Singleton;
            }
            else if (readChar == -1)
            {
                args.State = ReaderEnd.Singleton;
            }
            else
            {
                throw Error.Unexpected(ErrorCode.UnexpectedChars, Constants.RecordSeparator, readChar);
            }
        }
예제 #4
0
        protected ReaderField ReadSkipOne(ReadArgs args, int expectedChar)
        {
            int readChar = args.ReadOne();

            if (readChar != expectedChar)
            {
                throw Error.Unexpected(ErrorCode.UnexpectedChars, expectedChar, readChar);
            }
            return(this);
        }
예제 #5
0
        public void Read(StreamReader sr, IRead callback)
        {
            ReadArgs args = new ReadArgs(sr, callback);

            do
            {
                args.State.Read(args);
            } while (args.State != ReaderEnd.Singleton);
            args.SetValues();
        }
예제 #6
0
        public override void Read(ReadArgs args)
        {
            // sequence no, opening quote of type name has been read,
            TypeDefRecord rec = new TypeDefRecord(args.CurrentSeqNo, base.ReadStringStrict(args, false), ReadMembers(args));

            args.SetupRecord(rec);
            args.Read.Read(rec);

            //ReadMembers(args, rec);
        }
예제 #7
0
        protected String ReadStringStrict(ReadArgs args, bool expectOpenEncl = true)
        {
            int readChar = 0;

            // opening encloser
            if (expectOpenEncl)
            {
                readChar = args.ReadOne();
                if (readChar != iStringEncl)
                {
                    throw Error.UnexpectedChars(Constants.StringFieldEncloser, Convert.ToChar(readChar));
                }
            }

            while (true)
            {
                readChar = args.ReadOne();
                if (readChar == iStringEncl)
                {
                    break;
                }
                else if (readChar == iStringEsc)
                {
                    readChar = args.ReadOne();
                    if (readChar == iStringEsc)
                    {
                        args.StrAppend(Constants.StringEscapeChar);
                    }
                    else if (readChar == iStringEncl)
                    {
                        args.StrAppend(Constants.StringFieldEncloser);
                    }
                    else if (readChar == -1)
                    {
                        throw new Error(ErrorCode.UnexpectedEOF);
                    }
                    else
                    {
                        throw new Error(ErrorCode.NotEscapeChar).AddData(ErrorDataKeys.Actual, Convert.ToChar(readChar));
                    }
                    continue;
                }
                else if (readChar >= 0)
                {
                    args.StrAppend((char)readChar);
                }
                else
                {
                    throw new Error(ErrorCode.UnexpectedEOF);
                }
            }
            return(args.StrGet());
        }
예제 #8
0
        protected Record ReadRef(ReadArgs args, bool checkFirstChar = true)
        {
            int readChar = 0;

            if (checkFirstChar)
            {
                readChar = args.ReadOne();
                if (readChar != iRefPrefix)
                {
                    throw Error.Unexpected(ErrorCode.UnexpectedChars, Constants.ReferencePrefix, readChar);
                }
            }

            long seqNo      = 0;
            long digitValue = 0;

            while (true)
            {
                readChar   = args.ReadOne();
                digitValue = readChar - iDigit0;
                if (digitValue >= 0 && digitValue < 10)
                {
                    seqNo = (seqNo * 10) + digitValue;
                }
                else if (readChar == iFieldSep)
                {
                    args.State = ReaderField.Singleton;
                    break;
                }
                else if (readChar == iRecordSep)
                {
                    args.State = ReaderNewRecord.Singleton;
                    break;
                }
                else if (readChar == -1)
                {
                    args.State = ReaderEnd.Singleton;
                    break;
                }
                else
                {
                    throw Error.Unexpected(ErrorCode.UnexpectedChars, readChar, digitValue);
                }
            }

            return(args.dcRecords[seqNo]);
        }
예제 #9
0
        public override void Read(ReadArgs args)
        {
            Record refRec = base.ReadRef(args, false);

            if (refRec.RecType != RecordType.TypeDef)
            {
                throw Error.Unexpected(ErrorCode.UnexpectedRecordType, RecordType.TypeDef, refRec.RecType);
            }

            TypeDefRecord  refType = refRec as TypeDefRecord;
            InstanceRecord rec     = new InstanceRecord(args.CurrentSeqNo, refType);

            args.SetupRecord(rec);
            args.Read.Read(rec);

            // base.ReadRef must have already set the next state
        }
예제 #10
0
        public int ReadDateTimeDigits(ReadArgs args, int len)
        {
            int value    = 0;
            int mapValue = 0;

            for (int ctr = 0; ctr < len; ctr++)
            {
                int readChar = args.ReadOne();
                mapValue = readChar - iDigit0;
                if (mapValue >= 0 && mapValue < 10)
                {
                    value = (value * 10) + mapValue;
                }
                else
                {
                    throw Error.Unexpected(ErrorCode.UnexpectedChars, '0', readChar);
                }
            }
            return(value);
        }
예제 #11
0
        private string[] ReadMembers(ReadArgs args)
        {
            // members
            int           readChar = 0;
            List <String> members  = new List <string>();

            while (true)
            {
                readChar = args.ReadOne();
                if (readChar == iFieldSep)
                {
                    members.Add(base.ReadStringStrict(args));
                }
                else if (readChar == iRecordSep)
                {
                    args.State = ReaderNewRecord.Singleton;
                    return(members.ToArray());
                }
                else
                {
                    throw Error.Unexpected(ErrorCode.UnexpectedChars, Constants.FieldSeparator, readChar);
                }
            }
        }
예제 #12
0
 // ideally, according to the design of the where loop,
 // this method should not get triggered
 public override void Read(ReadArgs args)
 {
     throw new Error(ErrorCode.NothingToRead);
 }
예제 #13
0
        protected void ReadNumber(ReadArgs args, int readChar)
        {
            long valueLong = 0;
            long multiply  = 1;
            bool isDecimal = false;

            if (readChar == iMinus)
            {
                multiply = -1;
                args.StrAppend((char)readChar);

                readChar = args.ReadOne();
            }

            do
            {
                int digitValue = readChar - iDigit0;
                if (digitValue >= 0 && digitValue < 10)
                {
                    valueLong = (valueLong * 10) + digitValue;
                    args.StrAppend((char)readChar);
                }
                else
                {
                    if (readChar == iDecimal)
                    {
                        args.StrAppend((char)readChar);
                        isDecimal = true;
                    }
                    else if (readChar == iFieldSep)
                    {
                        args.State = ReaderField.Singleton;
                    }
                    else if (readChar == iRecordSep)
                    {
                        args.State = ReaderNewRecord.Singleton;
                    }
                    else if (readChar == -1)
                    {
                        args.State = ReaderEnd.Singleton;
                    }
                    else
                    {
                        throw Error.Unexpected(ErrorCode.UnexpectedChars, iDigit0, readChar);
                    }
                    break;
                }
                readChar = args.ReadOne();
            } while (true);

            ValueRecord vr = args.ValueRec;

            if (!isDecimal)
            {
                valueLong *= multiply;
                args.AddValue(valueLong);
                args.Read.GetReadValue().ReadValue(vr, args.valPos, valueLong);
                args.StrReset();
            }
            else
            {
                // get a double value
                do
                {
                    readChar = args.ReadOne();
                    int digitValue = readChar - iDigit0;
                    if (digitValue >= 0 && digitValue < 10)
                    {
                        args.StrAppend((char)readChar);
                    }
                    else
                    {
                        if (readChar == iFieldSep)
                        {
                            args.State = ReaderField.Singleton;
                        }
                        else if (readChar == iRecordSep)
                        {
                            args.State = ReaderNewRecord.Singleton;
                        }
                        else if (readChar == -1)
                        {
                            args.State = ReaderEnd.Singleton;
                        }
                        else
                        {
                            throw Error.Unexpected(ErrorCode.UnexpectedChars, iDigit0, readChar);
                        }
                        break;
                    }
                } while (true);

                double realValue = double.Parse(args.StrGet());
                args.AddValue(realValue);
                args.Read.GetReadValue().ReadValue(vr, args.valPos, realValue);
            }
        }
예제 #14
0
        public override void Read(ReadArgs args)
        {
            IReadValue  rv = args.Read.GetReadValue();
            ValueRecord vr = args.ValueRec;

            int readChar = args.ReadOne();

            switch (readChar)
            {
            case iBoolTrue:
                args.AddValue(true);
                rv.ReadValue(vr, args.valPos, true);
                break;

            case iBoolFalse:
                args.AddValue(false);
                rv.ReadValue(vr, args.valPos, false);
                break;

            case iStringEncl:
                String str = base.ReadStringStrict(args, false);
                args.AddValue(str);
                rv.ReadValue(vr, args.valPos, str);
                break;

            case iRefPrefix:
                Record rc = base.ReadRef(args, false);
                if (rc.RecType != RecordType.Instance && rc.RecType != RecordType.Array)
                {
                    throw Error.UnexpectedRecordType(RecordType.Instance, rc.RecType);
                }
                args.AddValue(rc);
                rv.ReadValue(vr, args.valPos, rc);
                return;

            case iDateTimePrefix:
                DateTime dt = new DateTime(
                    ReadDateTimeDigits(args, 4),
                    ReadDateTimeDigits(args, 2),
                    ReadDateTimeDigits(args, 2),
                    ReadSkipOne(args, iDateTimeT).ReadDateTimeDigits(args, 2),
                    ReadDateTimeDigits(args, 2),
                    ReadDateTimeDigits(args, 2),
                    ReadDateTimeDigits(args, 3)
                    );
                args.AddValue(dt);
                rv.ReadValue(vr, args.valPos, dt);
                break;

            case iFieldSep:
                args.AddValue(null);
                rv.ReadValueNull(vr, args.valPos);
                return;

            case iRecordSep:
                args.AddValue(null);
                rv.ReadValueNull(vr, args.valPos);
                args.State = ReaderNewRecord.Singleton;
                return;

            case -1:
                args.AddValue(null);
                rv.ReadValueNull(vr, args.valPos);
                args.State = ReaderEnd.Singleton;
                return;

            default:
                ReadNumber(args, readChar);
                return;
            }

            // fixed width values (bool, datetime) or values with delimiter (string)
            // still have one extra character to read in order to determine next step
            readChar = args.ReadOne();
            if (readChar == iFieldSep)
            {
                args.State = ReaderField.Singleton;
            }
            else if (readChar == iRecordSep)
            {
                args.State = ReaderNewRecord.Singleton;
            }
            else if (readChar == -1)
            {
                args.State = ReaderEnd.Singleton;
            }
            else
            {
                throw Error.UnexpectedChars(Constants.FieldSeparator, (char)readChar);
            }
        }
예제 #15
0
 abstract public void Read(ReadArgs args);