module structs; private { import std.array; import std.bitmanip; import std.system; /++ + Supported format types +/ enum FORMAT_TYPE { INT_8, /// Signed integer 8 bit INT_16, /// Signed integer 16 bit INT_32, /// Signed integer 32 bit INT_64, /// Signed integer 64 bit UINT_8, /// Unsigned integer 8 bit UINT_16, /// Unsigned integer 16 bit UINT_32, /// Unsigned integer 32 bit UINT_64, /// Unsigned integer 64 bit STRING /// C-String } /++ + A element of a package +/ struct Element { Endian endian; /// The endian to use bool isArray; /// If it's an array size_t arraySize; /// Array size 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; } } /++ + Removes the whitespaces of the string. + Params: + source = The source string to format + Returns: String without whitespaces +/ pure string remove_whitespaces(string source) { return source.replace(" ", ""); } // Test remove whitespaces. unittest { assert(remove_whitespaces(" a b c ") == "abc"); } } public { }