Save to a file: B64E, Zlib compressed MessagePack.
ASTER::ACTION::JSON::Serialize w/ MessagePack & Save to a file
JSON data currently in memory is stored in a file.
Binary data is stored as text data encoded in Base64. Since the binary is compressed with zlib before being serialized, the data size is reduced.
Parameter.1: Destination path of a file
ASTER rev.1.0.5 allows users to freely configure the data storage location. However, due to security concerns, future updates may change the specifications and restrict file storage destinations.
"./aster/savedata/b64eMsgPack.txt"
JSON is a text-based data format, but MessagePack is a format that allows handling it in binary form.
The conversion to MessagePack uses nlohmann/json’s to_msgpack.
Relevant URL :
Generally, even without compression, converting JSON to MessagePack results in a smaller data size compared to JSON.
Data that contains a large number of numerical values benefits from binary representation, allowing for efficient reduction of data size.
For example, in nlohmann/json, there is a default setting when storing numbers in JSON, where all floating-point numbers are serialized as Double type strings.
Relevant URLs
/// a class to store JSON values
/// @sa https://json.nlohmann.me/api/basic_json/
template<template<typename U, typename V, typename... Args> class ObjectType =
std::map,
template<typename U, typename... Args> class ArrayType = std::vector,
class StringType = std::string, class BooleanType = bool,
class NumberIntegerType = std::int64_t,
class NumberUnsignedType = std::uint64_t,
class NumberFloatType = double,// <-------------------------------------------:
template<typename U> class AllocatorType = std::allocator,
template<typename T, typename SFINAE = void> class JSONSerializer =
adl_serializer,
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError
class CustomBaseClass = void>
class basic_json;
MessagePack stores numerical data in the most optimal format—whether as integers or floating-point numbers—when converting to binary. This alone helps reduce data size.
JSON inherently includes essential characters such as "
(double quotes), :
(colon), and {}
(curly brackets) to define its data structure. MessagePack replaces these structural elements with binary identifiers and tags, effectively reducing redundant notation.
Comparison of Compression Technologies
Compression Method | Cmp Ratio | Speed | Extraction Speed | Characteristics |
---|---|---|---|---|
zlib | High | Medium | Medium | Versatile, nearly standard in PHP8 |
gzip | High | Slow | Medium | Similar to zlib, file-oriented |
ZIP | Medium | Medium | Medium | Good for multiple files |
zstd | Low | Fast | Fast | High-speed archiving |
LZ4 | Low | Very Fast | Very Fast | Speed-focused, lower ratio |
Starting from ASTER rev.1.0.5, data compression and decompression support zlib and LZ4. Since the decompression process for compressed data is publicly available as a Python 3 implementation, stored data can be used in other environments.
Python3 Implementation: Zlib version
Since the data is not encrypted, it remains editable for general developers. However, for regular users, modifying the stored data becomes difficult, making it somewhat more resistant to tampering compared to saving JSON in plain text.