Add string type

master
Marko Semet 2020-05-27 11:43:08 +02:00
parent 60154c0217
commit 53c0d2e130
1 changed files with 37 additions and 3 deletions

View File

@ -9,7 +9,7 @@ private
/++
+ Supported format types
+/
enum FormatType
enum FORMAT_TYPE
{
INT_8, /// Signed integer 8 bit
INT_16, /// Signed integer 16 bit
@ -18,7 +18,8 @@ private
UINT_8, /// Unsigned integer 8 bit
UINT_16, /// Unsigned integer 16 bit
UINT_32, /// Unsigned integer 32 bit
UINT_64 /// Unsigned integer 64 bit
UINT_64, /// Unsigned integer 64 bit
STRING /// C-String
}
/++
@ -29,7 +30,40 @@ private
Endian endian; /// The endian to use
bool isArray; /// If it's an array
size_t arraySize; /// Array size
FormatType formatType; /// The formated type
FORMAT_TYPE formatType; /// The formated type
/++
+ Calculate the size of the element
+ Returns: Size in bytes
+/
size_t packSize() const
{
// Base format type size
size_t base_size = 0;
final switch(this.formatType)
{
case FORMAT_TYPE.STRING:
case FORMAT_TYPE.INT_8:
case FORMAT_TYPE.UINT_8:
base_size = 1;
break;
case FORMAT_TYPE.INT_16:
case FORMAT_TYPE.UINT_16:
base_size = 2;
break;
case FORMAT_TYPE.INT_32:
case FORMAT_TYPE.UINT_32:
base_size = 4;
break;
case FORMAT_TYPE.INT_64:
case FORMAT_TYPE.UINT_64:
base_size = 8;
break;
}
// Add array size
return base_size * this.arraySize;
}
}
/++