コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
ファイル: Reader.cs プロジェクト: rdadbhawala/csn.net
        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());
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: Reader.cs プロジェクト: rdadbhawala/csn.net
        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]);
        }
コード例 #6
0
ファイル: Reader.cs プロジェクト: rdadbhawala/csn.net
        protected ReaderField ReadSkipOne(ReadArgs args, int expectedChar)
        {
            int readChar = args.ReadOne();

            if (readChar != expectedChar)
            {
                throw Error.Unexpected(ErrorCode.UnexpectedChars, expectedChar, readChar);
            }
            return(this);
        }
コード例 #7
0
ファイル: Reader.cs プロジェクト: rdadbhawala/csn.net
        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);
        }
コード例 #8
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);
                }
            }
        }
コード例 #9
0
ファイル: Reader.cs プロジェクト: rdadbhawala/csn.net
        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);
            }
        }
コード例 #10
0
ファイル: Reader.cs プロジェクト: rdadbhawala/csn.net
        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);
            }
        }