@@ -80,43 +80,46 @@ object CalculateSeqSizes {
80
80
* Determines how many bits occupies given data type.
81
81
*
82
82
* @param dataType data type to analyze
83
- * @return number of bits or None , if it's impossible to determine a priori
83
+ * @return number of bits or [[ DynamicSized ]] , if it's impossible to determine a priori
84
84
*/
85
85
def dataTypeBitsSize (dataType : DataType ): Sized = {
86
86
dataType match {
87
87
case BitsType1 (_) => FixedSized (1 )
88
- case BitsType (width, _) => FixedSized (width)
88
+ case CalcBooleanType => DynamicSized
89
+
89
90
case EnumType (_, basedOn) => dataTypeBitsSize(basedOn)
91
+
90
92
case ut : UserTypeInstream => getSeqSize(ut.classSpec.get)
91
- case _ =>
92
- dataTypeByteSize(dataType) match {
93
- case FixedSized (x) => FixedSized (x * 8 )
94
- case otherSize => otherSize
95
- }
96
- }
97
- }
93
+ case ut : UserTypeFromBytes => dataTypeBitsSize(ut.bytes)
94
+ case ut : CalcUserTypeFromBytes => dataTypeBitsSize(ut.bytes)
95
+ case _ : StructType => DynamicSized
96
+
97
+ case BitsType (width, _) => FixedSized (width)
98
+ case Int1Type (_) => FixedSized (8 )
99
+ case IntMultiType (_, width, _) => FixedSized (width.width * 8 )
100
+ case CalcIntType => DynamicSized
101
+
102
+ case FloatMultiType (width, _) => FixedSized (width.width * 8 )
103
+ case CalcFloatType => DynamicSized
98
104
99
- /**
100
- * Determines how many bytes occupies a given data type.
101
- *
102
- * @param dataType data type to analyze
103
- * @return number of bytes or None, if it's impossible to determine a priori
104
- */
105
- def dataTypeByteSize (dataType : DataType ): Sized = {
106
- dataType match {
107
- case _ : Int1Type => FixedSized (1 )
108
- case IntMultiType (_, width, _) => FixedSized (width.width)
109
- case FloatMultiType (width, _) => FixedSized (width.width)
110
105
case _ : BytesEosType => DynamicSized
111
106
case blt : BytesLimitType => blt.size.evaluateIntConst match {
112
- case Some (x) => FixedSized (x.toInt)
107
+ case Some (x) => FixedSized (x.toInt * 8 )
113
108
case None => DynamicSized
114
109
}
115
110
case _ : BytesTerminatedType => DynamicSized
116
- case StrFromBytesType (basedOn, _, _) => dataTypeByteSize(basedOn)
117
- case utb : UserTypeFromBytes => dataTypeByteSize(utb.bytes)
118
- case cutb : CalcUserTypeFromBytes => dataTypeByteSize(cutb.bytes)
111
+ case CalcBytesType => DynamicSized
112
+
113
+ case StrFromBytesType (basedOn, _, _) => dataTypeBitsSize(basedOn)
114
+ case CalcStrType => DynamicSized
115
+
119
116
case st : SwitchType => DynamicSized // FIXME: it's really possible get size if st.hasSize
117
+
118
+ case OwnedKaitaiStreamType | KaitaiStreamType => DynamicSized
119
+
120
+ // TODO: Add special type or attribute to ArrayType for arrays of known size
121
+ case _ : ArrayType => DynamicSized
122
+ case AnyType => DynamicSized
120
123
}
121
124
}
122
125
}
0 commit comments