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