private T[] GetFieldValueArray <T>(BitReader r, FieldMetaData fieldMeta, ColumnMetaData columnMeta, Value32[] palletData, Dictionary <uint, Value32> commonData, int arraySize) where T : struct { 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.ReadValue64(bitSize).GetValue <T>(); } else { arr1[i] = r.ReadValue64(columnMeta.Immediate.BitWidth).GetValue <T>(); } } return(arr1); case CompressionType.Immediate: T[] arr2 = new T[arraySize]; for (int i = 0; i < arr2.Length; i++) { arr2[i] = r.ReadValue64(columnMeta.Immediate.BitWidth).GetValue <T>(); } 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].GetValue <T>(); } return(arr3); } throw new Exception(string.Format("Unexpected compression type {0}", columnMeta.CompressionType)); }
private T GetFieldValue <T>(BitReader r, FieldMetaData fieldMeta, ColumnMetaData columnMeta, Value32[] palletData, Dictionary <uint, Value32> commonData) where T : struct { switch (columnMeta.CompressionType) { case CompressionType.None: int bitSize = 32 - fieldMeta.Bits; if (bitSize > 0) { return(r.ReadValue64(bitSize).GetValue <T>()); } else { return(r.ReadValue64(columnMeta.Immediate.BitWidth).GetValue <T>()); } case CompressionType.Immediate: return(r.ReadValue64(columnMeta.Immediate.BitWidth).GetValue <T>()); case CompressionType.Common: if (commonData.TryGetValue(Id, out Value32 val)) { return(val.GetValue <T>()); } else { return(columnMeta.Common.DefaultValue.GetValue <T>()); } case CompressionType.Pallet: uint palletIndex = r.ReadUInt32(columnMeta.Pallet.BitWidth); T val1 = palletData[palletIndex].GetValue <T>(); return(val1); } throw new Exception(string.Format("Unexpected compression type {0}", columnMeta.CompressionType)); }