Files
fs2open.github.com/code/scripting/api/objs/bytearray.cpp
T
asarium cf4fe8accc Add Lua API for serializing values
This can be used by script code for reliably storing Lua values without
having to build a custom serialization format.

The C++ code can also be used by other code modules that want to
serialize data. The new classes simply return a byte array with an
unspecified format.

At the moment this uses a plain JSON encoding but could be extended in
the future to include either compression or BSON encoding if necessary.
The format is future compatible by using a simple header to identify
different kinds of formats.
2020-09-12 14:28:16 +02:00

28 lines
697 B
C++

#include "bytearray.h"
namespace scripting {
namespace api {
bytearray_h::bytearray_h() = default;
bytearray_h::bytearray_h(SCP_vector<uint8_t> data) : m_data(std::move(data)) {}
const SCP_vector<uint8_t>& bytearray_h::data() const
{
return m_data;
}
//**********HANDLE: bytearray
ADE_OBJ(l_Bytearray, bytearray_h, "bytearray", "An array of binary data");
ADE_FUNC(__len, l_Bytearray, nullptr, "The number of bytes in this array", "number", "The length in bytes")
{
bytearray_h* array = nullptr;
if (!ade_get_args(L, "o", l_Bytearray.GetPtr(&array))) {
return ade_set_args(L, "i", 0);
}
return ade_set_args(L, "i", array->data().size());
}
} // namespace api
} // namespace scripting