Closed Lazrius closed 2 months ago
You could try to have the array as a ReflectionType in your VectorImpl:
https://github.com/getml/reflect-cpp/blob/main/docs/custom_classes.md
C arrays are tricky, because they can't be copied, but std::array will most certainly work.
Forgot to follow up, my apologies.
This is the code we used in the end and it worked very well, thank you again.
struct VectorImpl
{
using ReflectionType = std::array<float, 3>;
std::array<float, 3> arr;
static VectorImpl from_class(const Vector& val) noexcept
{
return VectorImpl{
{ val.x, val.y, val.z }
};
}
[[nodiscard]]
Vector to_class() const
{
return Vector{ arr[0], arr[1], arr[2] };
}
};
template <class ReaderType, class WriterType, class ProcessorsType>
struct Parser<ReaderType, WriterType, Vector, ProcessorsType> : CustomParser<ReaderType, WriterType, ProcessorsType, Vector, VectorImpl>
{};
Hello again. I've read the documentation quite a bit and don't think I've missed it, but I was wondering if it is possible to convert an object into an array type for the purposes of serialization and then convert it back into an object when going the other way around?
An example: We have an internal Vector class that represents three float values. I wrote the following code to handle it, but it's less than ideal:
which when passing in some example vectors, we get the following json:
Obviously not perfect. We'd more be looking for the following:
Is this possible, and if so, do you know what I need to change to make it happen?
Thanks again for your great project!