/// Depending on the data type and the compression level used the amount of
/// bits used and loss change.
///
///
/// ## Bool
/// Always use 1 bit
///
///
/// ## Int
/// COMPRESSION_LEVEL_0: 64 bits are used - Stores integers -9223372036854775808 / 9223372036854775807
/// COMPRESSION_LEVEL_1: 32 bits are used - Stores integers -2147483648 / 2147483647
/// COMPRESSION_LEVEL_2: 16 bits are used - Stores integers -32768 / 32767
/// COMPRESSION_LEVEL_3: 8 bits are used - Stores integers -128 / 127
///
///
/// ## Real
/// Precision depends on an integer range
/// COMPRESSION_LEVEL_0: 64 bits are used - Double precision. Up to 16 precision is 0.00000000000000177636 in worst case. Up to 512 precision is 0.00000000000005684342 in worst case. Up to 1024 precision is 0.00000000000011368684 in worst case.
/// COMPRESSION_LEVEL_1: 32 bits are used - Single precision (float). Up to 16 precision is 0.00000095367431640625 in worst case. Up to 512 precision is 0.000030517578125 in worst case. Up to 1024 precision is 0.00006103515625 in worst case.
/// COMPRESSION_LEVEL_2: 16 bits are used - Half precision. Up to 16 precision is 0.0078125 in worst case. Up to 512 precision is 0.25 in worst case. Up to 1024 precision is 0.5.
/// COMPRESSION_LEVEL_3: 8 bits are used - Minifloat: Up to 2 precision is 0.125. Up to 4 precision is 0.25. Up to 8 precision is 0.5.
///
/// To get the exact precision for the stored number, you need to find the lower power of two relative to the number and divide it by 2^mantissa_bits.
/// To get the mantissa or exponent bits for a specific compression level, you can use the get_mantissa_bits and get_exponent_bits functions.
///
///
/// ## Positive unit real
/// COMPRESSION_LEVEL_0: 10 bits are used - Max loss ~0.005%
/// COMPRESSION_LEVEL_1: 8 bits are used - Max loss ~0.020%
/// COMPRESSION_LEVEL_2: 6 bits are used - Max loss ~0.793%
/// COMPRESSION_LEVEL_3: 4 bits are used - Max loss ~3.333%
///
///
/// ## Unit real (uses one extra bit for the sign)
/// COMPRESSION_LEVEL_0: 11 bits are used - Max loss ~0.005%
/// COMPRESSION_LEVEL_1: 9 bits are used - Max loss ~0.020%
/// COMPRESSION_LEVEL_2: 7 bits are used - Max loss ~0.793%
/// COMPRESSION_LEVEL_3: 5 bits are used - Max loss ~3.333%
///
///
/// ## Vector2
/// COMPRESSION_LEVEL_0: 2 * 64 bits are used - Double precision (will fallback to level 1 if REAL_T_IS_DOUBLE is not defined)
/// COMPRESSION_LEVEL_1: 2 * 32 bits are used - Single precision
/// COMPRESSION_LEVEL_2: 2 * 16 bits are used - Half precision
/// COMPRESSION_LEVEL_3: 2 * 8 bits are used - Minifloat
///
/// For floating point precision, check the Real compression section.
///
///
/// ## Normalized Vector2
/// COMPRESSION_LEVEL_0: 12 bits are used - Max loss 0.17°
/// COMPRESSION_LEVEL_1: 11 bits are used - Max loss 0.35°
/// COMPRESSION_LEVEL_2: 10 bits are used - Max loss 0.7°
/// COMPRESSION_LEVEL_3: 9 bits are used - Max loss 1.1°
///
///
/// ## Vector3
/// COMPRESSION_LEVEL_0: 3 * 64 bits are used - Double precision (will fallback to level 1 if REAL_T_IS_DOUBLE is not defined)
/// COMPRESSION_LEVEL_1: 3 * 32 bits are used - Single precision
/// COMPRESSION_LEVEL_2: 3 * 16 bits are used - Half precision
/// COMPRESSION_LEVEL_3: 3 * 8 bits are used - Minifloat
///
/// For floating point precision, check the Real compression section.
///
///
/// ## Normalized Vector3
/// COMPRESSION_LEVEL_0: 11 * 3 bits are used - Max loss ~0.005% per axis
/// COMPRESSION_LEVEL_1: 9 * 3 bits are used - Max loss ~0.020% per axis
/// COMPRESSION_LEVEL_2: 7 * 3 bits are used - Max loss ~0.793% per axis
/// COMPRESSION_LEVEL_3: 5 * 3 bits are used - Max loss ~3.333% per axis
///
/// ## Variant
/// It's dynamic sized. It's not possible to compress it.
enumCompressionLevel{
COMPRESSION_LEVEL_0,
COMPRESSION_LEVEL_1,
COMPRESSION_LEVEL_2,
COMPRESSION_LEVEL_3
};
private:
intmetadata_size=0;
intbit_offset=0;
intbit_size=0;
boolis_reading=false;
BitArraybuffer;
public:
staticvoid_bind_methods();
DataBuffer()=default;
DataBuffer(constDataBuffer&p_other);
DataBuffer(constBitArray&p_buffer);
constBitArray&get_buffer()const{
returnbuffer;
}
BitArray&get_buffer_mut(){
returnbuffer;
}
/// Begin write.
voidbegin_write(intp_metadata_size);
/// Make sure the buffer takes least space possible.
voiddry();
/// Seek the offset to a specific bit. Seek to a bit greater than the actual