Exemple #1
0
        public object DecodeBinaryField(sbyte[] buf,
                                        int offset,
                                        int length)
        {
            var vals = new ArrayList <IsoValue>(parsers.Count);
            var pos  = offset;

            try
            {
                foreach (var fpi in parsers)
                {
                    var v = fpi.ParseBinary(0,
                                            buf,
                                            pos,
                                            fpi.Decoder);
                    if (v == null)
                    {
                        continue;
                    }
                    if (v.Type == IsoType.NUMERIC || v.Type == IsoType.DATE10 || v.Type == IsoType.DATE4 ||
                        v.Type == IsoType.DATE_EXP || v.Type == IsoType.AMOUNT || v.Type == IsoType.TIME ||
                        v.Type == IsoType.DATE12 || v.Type == IsoType.DATE14)
                    {
                        pos += v.Length / 2 + v.Length % 2;
                    }
                    else
                    {
                        pos += v.Length;
                    }
                    switch (v.Type)
                    {
                    case IsoType.LLVAR:
                    case IsoType.LLBIN:
                        pos++;
                        break;

                    case IsoType.LLLVAR:
                    case IsoType.LLLBIN:
                    case IsoType.LLLLVAR:
                    case IsoType.LLLLBIN:
                        pos += 2;
                        break;
                    }
                    vals.Add(v);
                }
                var f = new CompositeField
                {
                    Values = vals
                };
                return(f);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #2
0
        public object DecodeField(string value)
        {
            var vals = new ArrayList <IsoValue>(parsers.Count);
            var buf  = value.GetSbytes();
            var pos  = 0;

            try
            {
                foreach (var fpi in parsers)
                {
                    var v = fpi.Parse(0,
                                      buf,
                                      pos,
                                      fpi.Decoder);
                    if (v == null)
                    {
                        continue;
                    }
                    pos += fpi.Encoding.GetBytes(v.ToString()).Length;
                    switch (v.Type)
                    {
                    case IsoType.LLVAR:
                    case IsoType.LLBIN:
                        pos += 2;
                        break;

                    case IsoType.LLLVAR:
                    case IsoType.LLLBIN:
                        pos += 3;
                        break;

                    case IsoType.LLLLBIN:
                    case IsoType.LLLLVAR:
                        pos += 4;
                        break;
                    }
                    vals.Add(v);
                }
                var f = new CompositeField
                {
                    Values = vals
                };
                return(f);
            }
            catch (Exception)
            {
                return(null);
            }
        }