Пример #1
0
        private static T[] GetFieldValueArray <T>(BitReader r, FieldMetaData fieldMeta, ColumnMetaData columnMeta, Value32[] palletData, Dictionary <int, Value32> commonData, int arraySize) where T : unmanaged
        {
            switch (columnMeta.CompressionType)
            {
            case CompressionType.None:
                int bitSize = 32 - fieldMeta.Bits;

                T[] arr1 = new T[arraySize];

                for (int i = 0; i < arr1.Length; i++)
                {
                    if (bitSize > 0)
                    {
                        arr1[i] = r.Read <T>(bitSize);
                    }
                    else
                    {
                        arr1[i] = r.Read <T>(columnMeta.Immediate.BitWidth);
                    }
                }

                return(arr1);

            case CompressionType.Immediate:
                T[] arr2 = new T[arraySize];

                for (int i = 0; i < arr2.Length; i++)
                {
                    arr2[i] = r.Read <T>(columnMeta.Immediate.BitWidth);
                }

                return(arr2);

            case CompressionType.PalletArray:
                int cardinality = columnMeta.Pallet.Cardinality;

                if (arraySize != cardinality)
                {
                    throw new Exception("Struct missmatch for pallet array field?");
                }

                uint palletArrayIndex = r.ReadUInt32(columnMeta.Pallet.BitWidth);

                T[] arr3 = new T[cardinality];

                for (int i = 0; i < arr3.Length; i++)
                {
                    arr3[i] = palletData[i + cardinality * (int)palletArrayIndex].As <T>();
                }

                return(arr3);
            }
            throw new Exception(string.Format("Unexpected compression type {0}", columnMeta.CompressionType));
        }
Пример #2
0
        private static T GetFieldValue <T>(int Id, BitReader r, FieldMetaData fieldMeta, ColumnMetaData columnMeta, Value32[] palletData, Dictionary <int, Value32> commonData) where T : unmanaged
        {
            switch (columnMeta.CompressionType)
            {
            case CompressionType.None:
                int bitSize = 32 - fieldMeta.Bits;
                if (bitSize > 0)
                {
                    return(r.Read <T>(bitSize));
                }
                else
                {
                    return(r.Read <T>(columnMeta.Immediate.BitWidth));
                }

            case CompressionType.Immediate:
                return(r.Read <T>(columnMeta.Immediate.BitWidth));

            case CompressionType.SignedImmediate:
                return(r.ReadSigned <T>(columnMeta.Immediate.BitWidth));

            case CompressionType.Common:
                if (commonData.TryGetValue(Id, out Value32 val))
                {
                    return(val.As <T>());
                }
                else
                {
                    return(columnMeta.Common.DefaultValue.As <T>());
                }

            case CompressionType.Pallet:
                uint palletIndex = r.ReadUInt32(columnMeta.Pallet.BitWidth);

                T val1 = palletData[palletIndex].As <T>();

                return(val1);
            }
            throw new Exception(string.Format("Unexpected compression type {0}", columnMeta.CompressionType));
        }