Add love.data module.

- Moved love.math.compress / decompress / decode / encode / hash to love.data.
- Changed love.data.compress/decompress to take the format argument first instead of second.
- Added love.data.newDataView. Returns a read-only subsection of an existing Data object.
- Added love.data.newByteData. Mostly useful in combination with LuaJIT's FFI as it has no extra methods currently.
- Added implementations of Lua 5.3's data packing APIs: love.data.packString / packData / unpack / getPackedSize.

Resolves issue #1336.
Resolves issue #1331.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-09-24 19:25:27 -03:00
parent bdf961e174
commit 90e86c329d
50 changed files with 2182 additions and 545 deletions
-63
View File
@@ -22,9 +22,6 @@
#define LOVE_MATH_MODMATH_H
#include "RandomGenerator.h"
#include "CompressedData.h"
#include "Compressor.h"
#include "HashFunction.h"
// LOVE
#include "common/Module.h"
@@ -55,13 +52,6 @@ struct Triangle
Vector2 a, b, c;
};
enum EncodeFormat
{
ENCODE_BASE64,
ENCODE_HEX,
ENCODE_MAX_ENUM
};
/**
* Triangulate a simple polygon.
*
@@ -98,59 +88,6 @@ static float noise2(float x, float y);
static float noise3(float x, float y, float z);
static float noise4(float x, float y, float z, float w);
/**
* Compresses a block of memory using the given compression format.
*
* @param format The compression format to use.
* @param rawdata The data to compress.
* @param level The amount of compression to apply (between 0 and 9.)
* A value of -1 indicates the default amount of compression.
* Specific formats may not use every level.
* @return The newly compressed data.
**/
CompressedData *compress(Compressor::Format format, Data *rawdata, int level = -1);
CompressedData *compress(Compressor::Format format, const char *rawbytes, size_t rawsize, int level = -1);
/**
* Decompresses existing compressed data into raw bytes.
*
* @param[in] data The compressed data to decompress.
* @param[out] decompressedsize The size in bytes of the decompressed data.
* @return The newly decompressed data (allocated with new[]).
**/
char *decompress(CompressedData *data, size_t &decompressedsize);
/**
* Decompresses existing compressed data into raw bytes.
*
* @param[in] format The compression format the data is in.
* @param[in] cbytes The compressed data to decompress.
* @param[in] compressedsize The size in bytes of the compressed data.
* @param[in,out] rawsize On input, the size in bytes of the original
* uncompressed data, or 0 if unknown. On return, the size in
* bytes of the newly decompressed data.
* @return The newly decompressed data (allocated with new[]).
**/
char *decompress(Compressor::Format format, const char *cbytes, size_t compressedsize, size_t &rawsize);
char *encode(EncodeFormat format, const char *src, size_t srclen, size_t &dstlen, size_t linelen = 0);
char *decode(EncodeFormat format, const char *src, size_t srclen, size_t &dstlen);
/**
* Hash the input, producing an set of bytes as output.
*
* @param[in] function The selected hash function.
* @param[in] input The input data to hash.
* @return An std::string of bytes, representing the result of the hash
* function.
**/
std::string hash(HashFunction::Function function, Data *input);
std::string hash(HashFunction::Function function, const char *input, uint64_t size);
bool getConstant(const char *in, EncodeFormat &out);
bool getConstant(EncodeFormat in, const char *&out);
class Math : public Module
{