Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="itemVal"></param>
        /// <param name="itemAttr"></param>
        /// <param name="itemLen"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public static Object deSerializeItemVal(byte[] itemVal, StorageAttribute itemAttr, int itemLen, FldStorage fieldStorage, ref int offset)
        {
            Object        val    = null;
            int           count  = 0;
            int           endIdx = 0;
            int           len    = 0;
            string        tmp    = string.Empty;
            StringBuilder suffixBuf;
            string        tempVal     = string.Empty;
            short         noOfPackets = 0;


            switch (itemAttr)
            {
            case StorageAttribute.ALPHA:
                count  = 4;
                endIdx = offset + count;
                tmp    = Manager.Environment.GetEncoding().GetString(itemVal, offset, count);
                len    = Convert.ToInt32(tmp, 16);

                count  = len;
                offset = endIdx;
                val    = Manager.Environment.GetEncoding().GetString(itemVal, offset, count);
                break;

            case StorageAttribute.UNICODE:
                count  = 4;
                endIdx = offset + count;
                tmp    = Manager.Environment.GetEncoding().GetString(itemVal, offset, count);
                len    = Convert.ToInt32(tmp, 16);

                count  = len * 2;
                offset = endIdx;
                val    = Encoding.Unicode.GetString(itemVal, offset, count);
                break;

            case StorageAttribute.BOOLEAN:
                count  = 4;
                endIdx = offset + count;
                tmp    = Manager.Environment.GetEncoding().GetString(itemVal, offset, count);
                len    = Convert.ToInt32(tmp, 16);

                count  = len;
                offset = endIdx;

                val = BitConverter.ToInt16(Manager.Environment.GetEncoding().GetBytes(Manager.Environment.GetEncoding().GetString(itemVal, offset, count)), 0);
                break;

            case StorageAttribute.BLOB:
                count       = 2;
                endIdx      = offset + count;
                tmp         = Manager.Environment.GetEncoding().GetString(itemVal, offset, count);
                noOfPackets = BitConverter.ToInt16(Manager.Environment.GetEncoding().GetBytes(Manager.Environment.GetEncoding().GetString(itemVal, offset, count)), 0);

                offset = endIdx;

                count  = 4;
                endIdx = offset + count;
                tmp    = Manager.Environment.GetEncoding().GetString(itemVal, offset, count);
                len    = Convert.ToInt32(tmp, 16);

                count  = len;
                offset = endIdx;

                if ((len & 0x8000) > 0)
                {
                    suffixBuf = new StringBuilder();
                    count     = getSpannedField(itemVal, len, offset, itemAttr, suffixBuf, false, noOfPackets);
                    tempVal   = suffixBuf.ToString();
                }
                else
                {
                    if (UtilStrByteMode.isLocaleDefLangDBCS())
                    {
                        tempVal = ISO_8859_1_Encoding.getInstance().GetString(itemVal, offset, count);
                    }
                    else
                    {
                        tempVal = Manager.Environment.GetEncoding().GetString(itemVal, offset, count);
                    }
                }

                switch (fieldStorage)
                {
                case FldStorage.AnsiBlob:
                case FldStorage.UnicodeBlob:
                    val = BlobType.getString(tempVal);
                    break;

                case FldStorage.Blob:
                    if (UtilStrByteMode.isLocaleDefLangDBCS())
                    {
                        val = ISO_8859_1_Encoding.getInstance().GetBytes(BlobType.removeBlobPrefix(tempVal));
                    }
                    else
                    {
                        val = Manager.Environment.GetEncoding().GetBytes(BlobType.removeBlobPrefix(tempVal));
                    }
                    break;
                }


                break;

            case StorageAttribute.NUMERIC:
            {
                count  = 4;
                endIdx = offset + count;
                tmp    = Manager.Environment.GetEncoding().GetString(itemVal, offset, count);
                len    = Convert.ToInt32(tmp, 16);

                count  = len;
                offset = endIdx;

                switch (fieldStorage)
                {
                case FldStorage.NumericFloat:
                case FldStorage.NumericSigned:
                    byte[] array = new byte[count];
                    Array.Copy(itemVal, offset, array, 0, array.Length);
                    if (fieldStorage == FldStorage.NumericFloat)
                    {
                        val = BitConverter.ToDouble(array, 0);
                    }
                    else
                    {
                        val = BitConverter.ToInt32(array, 0);
                    }
                    break;

                case FldStorage.NumericPackedDec:
                case FldStorage.NumericString:
                    val = Manager.Environment.GetEncoding().GetString(itemVal, offset, count);
                    break;
                }
            }

            break;

            case StorageAttribute.TIME:
            case StorageAttribute.DATE:
                count  = 4;
                endIdx = offset + count;
                tmp    = Manager.Environment.GetEncoding().GetString(itemVal, offset, count);
                len    = Convert.ToInt32(tmp, 16);

                count  = len;
                offset = endIdx;
                switch (fieldStorage)
                {
                case FldStorage.TimeInteger:
                case FldStorage.DateInteger:
                    val = BitConverter.ToInt32(Manager.Environment.GetEncoding().GetBytes(Manager.Environment.GetEncoding().GetString(itemVal, offset, count)), 0);
                    break;

                case FldStorage.TimeString:
                case FldStorage.DateString:
                    val = Manager.Environment.GetEncoding().GetString(itemVal, offset, count);
                    break;
                }

                break;
            }

            offset = offset + count;

            return(val);
        }